Question for the MS guys (and gals) :)
I've always wondered about this--
Why is the DoEvents() function in the System.Windows.Forms.Application namespace?
I only ask because I do a lot of console apps for testing, and I always have to add the System.Windows.Forms dll to the project so I can get the DoEvents() functionality. Not using it in my long-running loops causes great system slow-down, so I definitely need it.
Thanks.
UPDATE
Joe, in my comments section, writes:
“DoEvents should not be used in a console app. If you have a CPU-bound console app like the example you gave, you can improve responsiveness of other apps by calling System.Threading.Thread.Sleep() in your loop. A short timeout is probably enough: just to relinquish your timeslice and let other processes in.”
So, I checked out the System.Threading.Thread.Sleep() function and the intellisense gives this little blurb about it:
“Specify Zero to indicate that this thread should be suspened to allow other waiting threads to execute.”
As Joe theorized, DoEvents() is probably just a wrapper around System.Threading.Thread.Sleep().
Mystery solved. Thanks to all that replied.