gpt4 book ai didi

multithreading - PowerShell 和单线程单元

转载 作者:行者123 更新时间:2023-12-02 23:30:24 24 4
gpt4 key购买 nike

我使用 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 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

从我的谷歌搜索中,STA 代表“单线程单元”,我注意到 powershell.exe 有“-sta”标志,但这也无济于事。

我的 ps1 文件的本质如下所示

Import-Module WPK

function get-gui()
{
New-Window -WindowStartupLocation CenterScreen `
-Width 1200 -Height 200 -Show {

New-Grid -Rows 32, 32, 32, 32 -Columns 110, 200* {
...
}
}
}
}

get-gui

有什么提示吗?

(我确实花了很多时间做自己的研究)

最佳答案

就这么简单! :) 感谢您的指导,Kayasax!

powerShell -sta -file PowerTools.ps1

关于multithreading - PowerShell 和单线程单元,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13623315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com