Updating UI from long-running process without dealing with threading

Quick tidbit learned in instructor-led class - Application.DoEvents() will cause UI to be updated. You can call this in the middle of a long-running process. For example, if I am going to process a bunch of data, and want to update status/progress information, the "cheaters" way to do it is to update these controls during the process, and then call Application.DoEvents() to fire the UI events so that the updates are visible. Otherwise, the UI isn't updated until the long-running process completes - which is kind of pointless. Of course, the right way to do this is with worker threads and Control.Invoke...
Published Wed, Sep 14 2005 2:06 AM by Joshua Langemann
Filed under:

Comments

Tuesday, September 13, 2005 11:02 PM by Nathan Pledger

# re: Updating UI from long-running process without dealing with threading

... as I did yesterday, for the first time! (Not often I get to do WinForms stuff)
Wednesday, September 14, 2005 1:47 AM by Jan Schreuder

# re: Updating UI from long-running process without dealing with threading

Just be carefull, because Application.DoEvents will not just fire UI events. It will allow all waiting events to be fired, including button clicks. Calling it too often will also decrease the performance of your application.

Mind you, I do it as well in my WinForm applications in long processes. Because sometimes it is the only way to force your UI to update in long processes.
Thursday, September 15, 2005 7:16 AM by Chris Slatt

# re: Updating UI from long-running process without dealing with threading

Indeed, coder beware with Application.DoEvents()

See here: http://www.codinghorror.com/blog/archives/000370.html
Monday, November 19, 2007 7:06 PM by Compunick

# re: Updating UI from long-running process without dealing with threading

Big Thanks!...I was playing around with threadging and BackgroundWorker.progress changed, but THIS was all I needed!

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 4 and 3 and type the answer here: