Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is equivalent to Application.DoEvents() in WPF applications

From MSDN, it seems that Application.DoEvents() is available in Windows.Forms. What would be the equivalent thing in WPF.

like image 369
Shamim Hafiz - MSFT Avatar asked Jul 21 '11 11:07

Shamim Hafiz - MSFT


People also ask

What is application DoEvents()?

Application. DoEvents() can be used to process the messages waiting in the queue on the UI thread when performing a long-running task in the UI thread. This has the benefit of making the UI seem more responsive and not "locked up" while a long task is running.

What is application DoEvents in VB net?

Application. DoEvents method has the same behavior as the DoEvents method. When you run a Windows Forms application, it creates a new form, which then waits for events to be handled. Each time the form handles an event, such as a button click, it processes all the code associated with that event.


2 Answers

You shouldn't be using it even in Windows Forms. Don't perform long-running tasks on the UI thread - use a background thread and use the Dispatcher to update the UI as required. Any use of Application.DoEvents is basically a code smell. I don't know whether there is an equivalent in WPF, but you should try to avoid it even if there is.

like image 144
Jon Skeet Avatar answered Oct 09 '22 13:10

Jon Skeet


While i agree with the Skeet you can find a WPF method like that on the documentation page of the DispatcherFrame

like image 32
H.B. Avatar answered Oct 09 '22 11:10

H.B.