[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.
Locked
User avatar
Bosparan
Posts: 282
Joined: Sun Mar 03, 2013 12:45 pm

[PSS 2017] Switch to MTA

Post by Bosparan » Sun Jan 22, 2017 2:49 pm

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

User avatar
DevinL
Site Admin
Posts: 1098
Joined: Mon Aug 17, 2015 2:25 pm

Re: [PSS 2017] Switch to MTA

Post by DevinL » Sun Jan 22, 2017 10:29 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: [PSS 2017] Switch to MTA

Post by davidc » Mon Jan 23, 2017 10:10 am

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 1514 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:

Code: Select all

# %ForceSTA% = False
David
SAPIEN Technologies, Inc.

User avatar
Bosparan
Posts: 282
Joined: Sun Mar 03, 2013 12:45 pm

Re: [PSS 2017] Switch to MTA

Post by Bosparan » Mon Jan 23, 2017 2:51 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: [PSS 2017] Switch to MTA

Post by davidc » Tue Jan 24, 2017 10:13 am

To disable STA globally, just uncheck it in the platform settings:
STA Mode.png
STA Mode.png (14.82 KiB) Viewed 1481 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.

User avatar
Bosparan
Posts: 282
Joined: Sun Mar 03, 2013 12:45 pm

Re: [PSS 2017] Switch to MTA

Post by Bosparan » Tue Jan 24, 2017 12:23 pm

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

Locked