I am working on my first GUI project with Powershell Studio 2015, and have run into an odd issue.

Let me preface this with saying, I have read the articles about creating responsive forms and have used that information extensively on my project.

Most of the functions that I have created in this script are stored in the globals.ps1 file, and the events on my forms call those functions.

I can run the entire application without fail from the IDE (i.e., clicking Run/Debug), but when I export the application to an executable, it fails at a very particular point. Essentially the form works in 3 high-level steps, each fired by a button control:

1) Query and select a target against which work will be performed
2) Collect credentials, authenticate against and open session to host
3) Do work

The first two steps work pretty well with good consistency, but the button to fire step 3 will cause the application to fail every single time.

I have tried adjusting the tasks that are actually carried out by the button (in the project, called $main_button_run) to more and more menial tasks in order to test and debug, but it fails regardless of what I configure it to do. Is there something i am missing here?

function LogRun-Setup
{
# Checks for presence of security group, creates/attaches if necessary.
# A PS session is opened for the LogRun task, the root working path is
# set and the start time is stored. A folder is created at the root
# working path.

The Add-RemoteJobTracker is a just a version of SAPIEN's Add-JobTracker that has been modified to use invoke-command in order to execute remote tasks, as well as to close the PSSessions when they are no longerneeded.

I can only recommend that you palce trace statements in the code and run it. Just output to a regular file for all of your write-debug lines. It is likely that assumptions made running in the IDE do not hold when running as a script. Try generating script to file and running the script in a CLI version of PS.

My issue was actually related to calling a SaveFileDialog, and my compiler was not using STA mode, which SAPIEN states is required for that control[1].

This actually brings me to another question, however, still related to the same thread subject.

I previously mentioned that I am leveraging a modified version of the JobTracker control set, and nearly all of my script actions are run as background jobs. That being said, there is a point where I need to wait for a number of background jobs to complete before script actions continue. The only way that I know how to do this would be wait-job, but that causes the gui form to hang/switch to not responding for the duration of the wait-job. Technically it's fine, but its a poor user experience.

I have a feeling that wait-job is the 'wrong' way to do this. Do you happen to have any alternative suggestions for waiting on jobs to complete without hanging the form?