Start-Sleep makes GUI unresponsive

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
CitrixITM
Posts: 124
Last visit: Wed Jul 27, 2022 2:19 pm

Start-Sleep makes GUI unresponsive

Post by CitrixITM »

In my GUI, I launch a script (in the background hidden) that downloads a file from an FTP server. The GUI checks the progress of the download and updates a progress bar. This is working well. I wanted to slow down the amount of times that the GUI updates the progress bar so I put a Start-Sleep 60 at the bottom of the loop so that it only updates the progress bar once per minute instead of continuously (continuously would cause the GUI to "Not Responding") . This works very well. However, when the system is "sleeping" for that minute, I am unable to move, resize, or close the GUI window. The GUI becomes unresponsive during this time.

Is there a way I can accomplish what I am trying to do without the GUI becoming unresponsive?

Thanks.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Start-Sleep makes GUI unresponsive

Post by jvierra »

Start-Sleep blocks all events. It is not intended for use in a GUI.

Consider changing the timer interrupt[t rate to a longer interval.
User avatar
CitrixITM
Posts: 124
Last visit: Wed Jul 27, 2022 2:19 pm

Re: Start-Sleep makes GUI unresponsive

Post by CitrixITM »

Thanks. I would love to do that, but not sure the way I am updating the progress bar is setup to do that. Could I do that looking at the below code?

while (($JobName.state -eq "running").count -gt 0)
{
$i = 0
foreach ($record in $WWCO)
{
$record1 = $record.name
try { $Percent = Get-Content "c:\Program Files (x86)\Citrix\ITM HelpDesk\FTP\$record1.xva.count" -ErrorAction SilentlyContinue } catch { }
if ($cent = $groupbox1.Controls.Find("progressbaroverlay$i", $false)) { $cent[0].Value = $Percent}
$i++
}
Start-Sleep 60
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Start-Sleep makes GUI unresponsive

Post by jvierra »

You cannot use "Start-Sleep" It will not work. The timer polls the jobs and adjusts the progress bar. There is no need to run in a loop.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Start-Sleep makes GUI unresponsive

Post by dan.potter »

Think about what start-sleep does when you run it in the shell. Can you run other commands while it is sleeping?

look in the toolbox, second tab (square with dots) and you find a couple items you can use for this.
This topic is 7 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked