Is there a way to programmatically set the ApartmentState to STA?

前端 未结 2 706
迷失自我
迷失自我 2021-01-02 21:20

I\'m working on a GUI in PowerShell where I was throwing errors when certain comboboxes were clicked.

After the error was thrown, I could drop the combobox list down

2条回答
  •  甜味超标
    2021-01-02 21:54

    If you have pscx installed, you can use Invoke-Apartment -Apartment STA -Expression { .... }.

    If not, have a look at WPF & PowerShell – Part 1 ( Hello World & Welcome to the Week of WPF ) where James creates runspace with STA. Another source might be Asynchronicity in PowerShell.

    Or some older posts about custom cmdlet Single Threaded Apartment in PowerShell V1.

提交回复
热议问题