Do not post any licensing information in this forum.
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?
Currently the code that is fired by a button click is as follows:
Write-Debug 'run clicked'
$main_label_elapsed_static.Visible = $false
$main_label_elapsed.Visible = $false
The function being called is stored in globals.ps1, and does the following:
# 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.
Write-Debug 'Logrun-Setup init'
$main_label_status.text = "Creating security group..."
$main_label_status.text = "Opening session..."
$global:jobList = @()
$global:startDTM = (Get-Date)
$global:RootPath = "c:\WorkSpacesLogs\"
$main_label_status.text = "Creating working directory..."
Write-Debug 'adding rootpath job'
Add-RemoteJobTracker -Name "CreateRootPath" -JobScript `
$global:RootPath = $args
Remove-Item $global:RootPath -recurse -Force -ErrorAction SilentlyContinue | out-null
New-Item $global:RootPath -type directory -force | out-null
} -ArgumentList $global:RootPath -CompletedScript `
Wait-Job -Name "CreateRootPath"
Write-Debug "LogRun-Setup Complete"
$main_label_status.text = "Gathering Workspace Logs..."
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.
Is there something stupid here that I am not seeing?
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.
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?
: https://www.sapien.com/blog/2015/03/09/ ... -sta-mode/
Who is online
Users browsing this forum: No registered users and 8 guests