[System.Windows.Forms.Application]::DoEvents()

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.
Locked
ClipperXTP
Posts: 55
Last visit: Thu Jun 24, 2021 3:05 am

[System.Windows.Forms.Application]::DoEvents()

Post by ClipperXTP »

Hi

Your thoughts on [System.Windows.Forms.Application]::DoEvents() and the below article?

https://www.sapien.com/blog/2011/07/15/ ... ive-loops/

It is a very old article and there is a lot of bad press about using [System.Windows.Forms.Application]::DoEvents()

My form and progress bar was not responsive when running a loop with a query of hundreds of machines using a runspacepool to do the leg work.

As soon as I inserted [System.Windows.Forms.Application]::DoEvents() in the loop, happy days, no freezing, progress bar and form are fine, I can even drag the form around the screen.
As long as I am disabling and re-enabling the buttons that trigger the query, is there any other considerations I need to have?

Thanks in advance

jvierra
Posts: 14931
Last visit: Wed Sep 22, 2021 3:44 pm
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: [System.Windows.Forms.Application]::DoEvents()

Post by jvierra »

Bad press? I read teh newspapers constantly. Never seen any press, good or bad, mention that.

Perhaps you are thinking about an old controversy from early days of VB where people would place a DoEvents after almost every line of code. You know, the old hack, if one pill is good than a thousand must be better.

ClipperXTP
Posts: 55
Last visit: Thu Jun 24, 2021 3:05 am

Re: [System.Windows.Forms.Application]::DoEvents()

Post by ClipperXTP »

Thank you

Locked