[2.0] Application.DoEvents
I'm primarily a web developer but have to dip into a few windows apps now and again as I am currently the only .net developer in my team.
A former collegue of mine used the following snippet very frequently:
Code:
for(int i=0;i<10;i++)
{
Application.DoEvents();
}
From my understanding Application.DoEvents tells windows to process all messages currently in it's queue so what is the benefit of looping it 10 times?
Re: [2.0] Application.DoEvents
Application.DoEvents() processes all the message sin the queue so the first call is enough. The only time it would be necessary to call that continuously in a loop is if you were doing something else like so...
Code:
for(int i=0;i<10;i++)
{
//TxtBox1.Text = "sssssssssss";
//TxtBox2.Text = "zzzzzzzzzzz";
Application.DoEvents();
}
That is needed because it has to allow the UI to update, otherwise calling it once is adequate.
Re: [2.0] Application.DoEvents
Thanks, I thought as much. I can't work out why the previous developer did this.
Re: [2.0] Application.DoEvents
I find that using Application.DoEvents() is a very...fishy way of keeping the UI responsive when executing big loops or something of the like.
In my opinion you should never execute such code in the main thread but rather do it in a worker thread.
Re: [2.0] Application.DoEvents
Quote:
Originally Posted by Fishcake
Thanks, I thought as much. I can't work out why the previous developer did this.
Maybe he thought you had to do it once for each potential message.
I agree with Atheist on its use.