SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 3 days 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
User avatar
grathal
Posts: 98
Last visit: Tue Nov 27, 2018 4:16 am

SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by grathal »

Hello,

I have a PS2012 project containing a button which calls SaveFileDialog.ShowDialog().

The AutoUpgradeEnabled property is set to True.

When I run the project in PS2012, it works fine.
If I export the project to a single file and run it from the commandline, it hangs when I press the button.

If I change AutoUpgradeEnabled to False in the project, then it works.

Is that normal on Windows 2008? Should I always set that property to False?

Thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

Also the File Dialogs require STA mode. When you set the value to true or leave it at the default the upgrade is attempted on 2008 (Vista and later). The UI requires STA with the wrapped dialogs.
User avatar
grathal
Posts: 98
Last visit: Tue Nov 27, 2018 4:16 am

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by grathal »

Thanks, I'm running on Windows 2008, not Vista, so why does it cause a problem? Is it a bug in Windows or PS2012?

Any idea how to run a PS2012 GUI script from the commandline in STA mode?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

It is the same on all vista and later systems. WS2008 is post-vista. It uses the Vista UI and the enhanced "chrome/aero" interface. IF you want to use the dialogs you must use an STA setting for PowerShell.

powershell -sta
User avatar
grathal
Posts: 98
Last visit: Tue Nov 27, 2018 4:16 am

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by grathal »

Ok thanks again.

I've exported the GUI script from PS2012 to a single file and it works fine without specifying the -sta on the commandline. So it must be set by default in 2008 or in the PS2012 export?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

Nope not what is happening. YOU cannot set the threading model in a script. It is set on the engine.

By default PowerShell runs STA. Some shortcuts may have -MTA set.

In PS2012 there is a button on the toolbar that toggles STA/MTA.

With all of that in mind go back and test. I suspect you are explain things a little bit off from what is happening.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

When you drop the file dialog control set onto your form you will see a message pop up. It says that "STA" mode is required. Apparently you missed the warning. Be sure STA mode is set in PS2012.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

When I run PS2012 project I get this banner in PS2012:
PowerShell Code
Double-click the code block to select all.
>> Running (Demo-MsoUsers.pff) Script...
>> Platform: V4 64Bit (STA) (Forced)
Even if I just drop the control on a new form PS2012 will force run the form in STA mode. If I copy the script to ths clipboard and paste into PowerShell running in MTA mode it will hang when the dialog is opened.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: SaveFileDialog with AutoUpgradeEnabled = True hangs ...

Post by jvierra »

Just to be sure I just ran the same tests on WS2008. THe default or STA mode of PowerShell has no issues.

If you are using PowerShell V2 ISE it may be running in MTA mode. I am not sure about that but I seem to remember that it runs that way in V2.
This topic is 10 years and 3 days 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