I create a form with a progress bar control set.
At the end I added an info msgbox.
Everything seems to work well, but I noticed that after I close the msgbox the main form remains "freezed" for a few seconds and you can not click on the buttons or even close with the x button.
After a few seconds instead you can go back to interacting with the main form.
Why does this happen? How can I solve?
Thank you
Code: Select all
$buttonCancelProcess_Click={
$script:CancelLoop = $true
}
$buttonStartProcess_Click={
#Init CancelLoop
$script:CancelLoop = $false
$buttonCancelProcess.Enabled = $true
#Disable the button so we don't trigger it again
$this.Enabled = $false
#Reset the Progress Bar
$progressbar1.Value = 0
for($i = 0; $i -lt $progressbar1.Maximum; $i++)
{
#----------------------------------------
#Place custom script here
sleep -Milliseconds 200
#----------------------------------------
#process the pending message
[System.Windows.Forms.Application]::DoEvents()
if($script:CancelLoop -eq $true)
{
#Clear the progress bar
$progressbar1.Value = 0
#Exit the loop
break;
}
#Step the progress bar
$progressbar1.PerformStep()
}
#Enable the button so we can click it again
$this.Enabled = $true
$buttonCancelProcess.Enabled = $false
#msgbox
$msg = '........'
[void][System.Windows.Forms.MessageBox]::Show($msg, 'Info', 'OK', 'Exclamation')
}