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
[PSS 2017] Switch to MTA
Forum rules
Do not post any licensing information in this forum.
Do not post any licensing information in this forum.
Re: [PSS 2017] Switch to MTA
Thanks for another suggestion Bosparan,
I'll put this on the wishlist and we'll reply if we get some more information.
I'll put this on the wishlist and we'll reply if we get some more information.
DevinL
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: [PSS 2017] Switch to MTA
If you are using a packaged executable, you can uncheck the STA Mode option in the Packager Settings:
If you want to disable STA Mode when running the script within PowerShell Studio, use the following comment near the top of the script:
If you want to disable STA Mode when running the script within PowerShell Studio, use the following comment near the top of the script:
- # %ForceSTA% = False
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: [PSS 2017] Switch to MTA
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
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
To disable STA globally, just uncheck it in the platform settings:
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.
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.
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: [PSS 2017] Switch to MTA
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
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