Problem with form refresh

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 6 years and 1 month 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
TonySpeight
Posts: 5
Last visit: Tue Mar 14, 2023 4:57 am

Problem with form refresh

Post by TonySpeight »

Hello,

I have created a form which is using robocopy to copy files.
I have a function which outputs to the progress bar which works fine, however after about 10 seconds into the job and then the form hangs. Although the form is hung the robocopy still carries on working. Once the job has finished the form responds again until around 10 seconds into the next job.

I have added the form refresh ($formname.refresh()) into the while loop whilst the job has a state of running.

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

Re: Problem with form refresh

Post by jvierra »

You cannot access a form from a job and you shouldn't try. Doing so can deadlock the form.
You cannot wait on a job in an event as it will freeze the form. Use the JobTracker control and your issues will be gone.
User avatar
TonySpeight
Posts: 5
Last visit: Tue Mar 14, 2023 4:57 am

Re: Problem with form refresh

Post by TonySpeight »

hello jvierra,

Thank you for your reply. I have just found an article explaining the JobTracker. I will give this a go.

Thanks
Tony
User avatar
TonySpeight
Posts: 5
Last visit: Tue Mar 14, 2023 4:57 am

Re: Problem with form refresh

Post by TonySpeight »

An update on my issue.

I have added the following line right after my while loop and this has fixed the issue.

[System.Windows.Forms.Application]::DoEvents()
This topic is 6 years and 1 month 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