Advertisement:

Skystone Software

http://www.SkystoneSoftware.com

Scott Waletzko's Blog
DoEvents in WPF
Published: 4/15/2009
XMl / RSS

So much has changed with the advent of WPF (Windows Presentation Framework), making developers rethink much of what they used to take for granted. One of those things is how to instruct your UI to pause for effect, which used to be implemented by a call to Application.DoEvents. The Dispatcher is now the manager responsible for threading operations in WPF programs, and I now add the following routine to the App class in my WPF programs to implement the same type of functionality as the old DoEvents function used to:

C#
public static void DoEvents()
{
    DispatcherFrame frame = new DispatcherFrame();
    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, 
        (SendOrPostCallback)delegate(object paramter)
            {
                DispatcherFrame parmFrame = paramter as DispatcherFrame;
                parmFrame.Continue = false;
            }
        , frame);
    Dispatcher.PushFrame(frame);
}	
	



Questions or Comments? .

VB to C# and C# to VB translation provided by Instant C# and Instant VB.