Page 1 of 1

Prevent Script from Freezing PS Studio 2019 form

Posted: Thu May 06, 2021 7:06 am
by mar10c
I am trying to prevent the form from freezing/unresponsive when the $output can't connect to remote computer. I need to set the timer to release the event back to the form.

$button1.Enabled = $false
$TotalTime = 10 #in seconds
$script:StartTime = (Get-Date).AddSeconds($TotalTime)
#Start the timer
$timerUpdate.Start()
[TimeSpan]$span = $script:StartTime - (Get-Date)
if ($span.TotalSeconds -le 0)
{
$timerUpdate.Stop()
}
$output = ssh user1@$remotecomputer

$button1.Enabled = $true

Re: Prevent Script from Freezing PS Studio 2019 form

Posted: Thu May 06, 2021 7:13 am
by jvierra
Events cannot be terminated. If a call blocks in an event you will just have to wait for completion or for a timeout. If it deadlocks then it is likely due to some system failure although third party software may not be well designed and may not prevent a complet4e freeze.

You can run scripts in a job and then kill the job if it hangs.

See: https://info.sapien.com/index.php/guis/ ... sive-forms