I have a form that runs a Progress Bar. I need to wait 32 minutes and so I was using the ProgressBar on my GUI form to display continued progress along with messages. I run through the Do/While, execute a 1 minute sleep, increment, and repeat until the variable increments to 32 (32 minutes therefore having passed). However, the form seems to freeze and lock up, unable to be moved or minimized, while the 1 minute sleep runs (so basically for 32 minutes)...
I've tried Start-Job and Wait-Job, but have a feeling I'm not utilizing it properly. I don't quite understand how to effectively take the 1 minute sleep and process it as a side-job on a different thread from a script standpoint.
The function that processes the loop & sleep:
function WaitSync {
#Removes all of the old controls
foreach ($control in $aControls2) {$MainForm.Controls.Remove($control)}
#Adds the progress bar and message
$MainForm.Controls.Add($pbSync)
$MainForm.Controls.Add($lPhrases)
#Initializes the increment variable
$z = 0
while ($z -le 33) {
$lPhrases.Text = "Updated Text..."
$pbSync.Value = $z
$pbSync.Refresh()
Start-Sleep -Seconds 60
$z++
}
#Adds the Complete Button to close the Form
$MainForm.Controls.Add($bComplete)
}
How do I make it so the form can be at least minimized while the progress bar processes (the 32 minutes wait out)?