Page 1 of 1
[PSS 2017] Switch to MTA
Posted: Sun Jan 22, 2017 1:49 pm
by Bosparan
Hi,
I recently stumbled over a slight issue: I ran some code in PowerShell Studio and it worked. When I pushed it into our toolkit however, it just wouldn't work. It took me a few minutes to figure out why it had failed when the first miniature test worked:
PSS always runs scripts in STA (Single Thread Apartment) mode. This was made the default in PS3+ and is more easily compatible with GUI elements, so I can totally understand why it's the default. Some of our work however is run in MTA mode (including the main toolkit), since it has some performance benefits. Would be great if I had an option to switch to MTA mode (and even better if I could configure that on a per-project basis) for script I run from within PSS.
Cheers,
Fred
Re: [PSS 2017] Switch to MTA
Posted: Sun Jan 22, 2017 9:29 pm
by DevinL
Thanks for another suggestion Bosparan,
I'll put this on the wishlist and we'll reply if we get some more information.
Re: [PSS 2017] Switch to MTA
Posted: Mon Jan 23, 2017 9:10 am
by davidc
If you are using a packaged executable, you can uncheck the STA Mode option in the Packager Settings:
- Packager Settings - STA Mode.png (58.62 KiB) Viewed 4004 times
If you want to disable STA Mode when running the script within PowerShell Studio, use the following comment near the top of the script:
Re: [PSS 2017] Switch to MTA
Posted: Mon Jan 23, 2017 1:51 pm
by Bosparan
Hi David,
thanks for the info on how to disable it for an entire file. I've tested it a bit and it works just fine ... if I run the entire file. But what if I only want to run the current selection?
I just tested it (Using Set-Clipboard, which only works in STA), and it works so long as any line of code in the selection contains it, however it will not work if the
selection rather than the file doesn't contain that file (and most of the code I run from within PSS is run using "Run Selection").
A short-term workaround is to create a snippet with that line and keybind it, but that's not really elegant, I think. Having a general toggle for that would certainly make it a lot easier for me.
On the other hand ... I don't think many people have this issue, so the workaround may have to do
Btw, can I somehow globally configure these system variables, or whatever they are, that you use to control behavior? I wouldn't mind switching to MTA for all my usage - I really don't use much STA-Only features, at least not intentionally.
Cheers,
Fred
Re: [PSS 2017] Switch to MTA
Posted: Tue Jan 24, 2017 9:13 am
by davidc
To disable STA globally, just uncheck it in the platform settings:
- STA Mode.png (14.82 KiB) Viewed 3971 times
Then just add the comment for the files that require STA.
Note: PowerShell Studio will automatically force STA when it detects a control that requires it in a psf file.
You can also update the ps1 file template to include the ForceSTA comment.
Re: [PSS 2017] Switch to MTA
Posted: Tue Jan 24, 2017 11:23 am
by Bosparan
Hi David,
thanks a lot for that pointer.
Another question: Just how the hell did I not see this button?!
That solves all the STA/MTA issues I had, thanks again.
Cheers,
Fred