Like, uh, whatever, I guess


  Wednesday, May 26, 2004
    [3:58:30 PM]


It's been a while since I wrote any VB, but I still remember the mysterious DoEvents statement, sometimes dropping it into some code sorted things out, sometimes it didn't, noone every really seemed to know.

So how surprised was I to find this lurking in someones C# code earlier? Very.


However after a quick Google search, this explanation popped up, which sounds sensible:

When you run a Windows Form, it creates the new form, which then waits for events to handle. Each time the form handles an event, it processes all the code associated with that event. All other events wait in the queue. While your code handles the event, your application does not respond. For example, the window does not repaint if another window is dragged on top.

If you call DoEvents in your code, your application can handle the other events. For example, if you have a form that adds data to a ListBox and add DoEvents to your code, your form repaints when another window is dragged over it. If you remove DoEvents from your code, your form will not repaint until the click event handler of the button is finished executing.

Typically, you use this method in a loop to process messages.

Microsoft reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsApplicationClassDoEventsTopic.asp

Comments: Post a Comment

November 2003
January 2004
February 2004
March 2004
April 2004
May 2004
June 2004

This page is powered by Blogger. Isn't yours?  Weblog Commenting and Trackback by HaloScan.com