Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading PowerShell和单线程公寓_Multithreading_Powershell_Batch File_Wpk - Fatal编程技术网

Multithreading PowerShell和单线程公寓

Multithreading PowerShell和单线程公寓,multithreading,powershell,batch-file,wpk,Multithreading,Powershell,Batch File,Wpk,我在PowerShell中使用开发了一个小型GUI工具 我有以下启动命令 powershell -ExecutionPolicy Unrestricted -file PowerTools.ps1 -noexit -sta 我得到以下错误 New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require

我在PowerShell中使用开发了一个小型GUI工具

我有以下启动命令

powershell -ExecutionPolicy Unrestricted -file PowerTools.ps1 -noexit -sta
我得到以下错误

New-Object : Exception calling ".ctor" with "0" argument(s): "The calling thread must be STA, because many UI components require this."
At \WindowsPowerShell\Modules\WPK\GeneratedControls\PresentationFramework.ps1:34
10 char:29
+         $Object = New-Object <<<<  System.Windows.Window
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId :     ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
有什么提示吗

(我确实花了不少时间做我自己的研究)

就这么简单吧!:)谢谢你的指导,Kayasax

powerShell -sta -file PowerTools.ps1

表示
-file
必须是选项列表中的最后一个,因为文件名之后的所有内容都被解释为文件的参数。这就是为什么当
-sta
列在
-file
之前时,它工作,但在
-file
之后不工作。为什么使用此批?只需像这样调用PS:
powershell.exe-ExecutionPolicy Unrestricted-file PowerTools.ps1-noexit
谢谢!我简化了上面的帖子。但我还是得到了和以前一样的错误:(有什么提示吗?请验证
[System.Management.Automation.Runspaces.Runspace]的AppartmentState]::DefaultRunspace
ISE中的“STA”,未知使用powershell.exe和一个ps1文件。请注意区别:我有
powershell-file PowerTools.ps1-sta
,但它不起作用。有人能解释一下区别吗?不知怎的,我的旧版本的sta与ps1文件关联,而我的新版本的sta与powershell关联?你可以查看这篇文章,其中脚本会检测pow是否存在ershell处于sta模式,如果不是这种情况,请重新启动
powerShell -sta -file PowerTools.ps1