I have developed a small GUI tool in PowerShell using WPK.
I have the following start up command
powershell -ExecutionPolicy Unrestricted -file PowerTools.ps1 -noexit -sta
I am getting the following error.
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
From my Googling, STA stands up "single-threaded apartment", I noticed that that powershell.exe has the "-sta" flag, but that does not help either.
The essence of my ps1 file looks like the following
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
Any hints please?
(I did spend quite a bit of time doing my own research)