|
-
Feb 22nd, 2008, 06:57 AM
#1
Thread Starter
Frenzied Member
[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?
-
Feb 22nd, 2008, 07:24 AM
#2
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.
-
Feb 22nd, 2008, 08:37 AM
#3
Thread Starter
Frenzied Member
Re: [2.0] Application.DoEvents
Thanks, I thought as much. I can't work out why the previous developer did this.
-
Feb 22nd, 2008, 08:46 AM
#4
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.
-
Feb 22nd, 2008, 08:58 AM
#5
Re: [2.0] Application.DoEvents
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|