[PSS 2017] Switch to MTA

Post feature requests, product enhancement ideas, and other product-specific suggestions here. Do not post bug reports.
Forum rules
Do not post any licensing information in this forum.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Bosparan
Posts: 290
Last visit: Fri Oct 08, 2021 11:59 am

[PSS 2017] Switch to MTA

Post 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
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: [PSS 2017] Switch to MTA

Post by DevinL »

Thanks for another suggestion Bosparan,

I'll put this on the wishlist and we'll reply if we get some more information.
DevinL
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: [PSS 2017] Switch to MTA

Post 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
Packager Settings - STA Mode.png (58.62 KiB) Viewed 3984 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:
  1. # %ForceSTA% = False
David
SAPIEN Technologies, Inc.
Bosparan
Posts: 290
Last visit: Fri Oct 08, 2021 11:59 am

Re: [PSS 2017] Switch to MTA

Post 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
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: [PSS 2017] Switch to MTA

Post by davidc »

To disable STA globally, just uncheck it in the platform settings:
STA Mode.png
STA Mode.png (14.82 KiB) Viewed 3951 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.
David
SAPIEN Technologies, Inc.
Bosparan
Posts: 290
Last visit: Fri Oct 08, 2021 11:59 am

Re: [PSS 2017] Switch to MTA

Post 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
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked