Note that there are some explanatory texts on larger screens.

plurals
  1. PODismiss a Powershell form controlled by a start-job task
    primarykey
    data
    text
    <p>I've been tasked with building a powershell script with a GUI which enables users to install network printers. I've succesfully managed to do so, but I cannot meet the requirement that the user be shown a 'please wait' window whilst the printers install. If I switch to the window from the main thread, the GUI hangs. If I move showing the window to a seperate job, I'm never able to close the window again. Here's my attempt:</p> <pre><code>$waitForm = New-Object 'System.Windows.Forms.Form' $CloseButton_Click={ # open "please wait form" Start-Job -Name waitJob -ScriptBlock $callWork -ArgumentList $waitForm #perform long-running (duration unknown) task of adding several network printers here $max = 5 foreach ($i in $(1..$max)){ sleep 1 # lock up the thread for a second at a time } # close the wait form - doesn't work. neither does remove-job $waitForm.Close() Remove-Job -Name waitJob -Force } $callWork ={ param $waitForm [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") $waitForm = New-Object 'System.Windows.Forms.Form' $labelInstallingPrintersPl = New-Object 'System.Windows.Forms.Label' $waitForm.Controls.Add($labelInstallingPrintersPl) $waitForm.ClientSize = '502, 103' $labelInstallingPrintersPl.Location = '25, 28' $labelInstallingPrintersPl.Text = "Installing printers - please wait..." $waitForm.ShowDialog($this) } </code></pre> <p>Does anyone know how I can dismiss the $waitForm window when the long-running task has concluded?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload