Articles in categories

Articles

WPF alternative for Application.DoEvents

With the Dispatcher.PushFrame Method you can simulate the Application.DoEvents Method which is present in  System.Windows.Forms assembly.

My static DoEvents class:

using System.Windows.Threading;

namespace Stieven.Utils
{
  public static class DoEvents
  {
    public static void Do()
    {
      DispatcherFrame frame = new DispatcherFrame();
      Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
          new DispatcherOperationCallback(ExitFrame), frame);
      Dispatcher.PushFrame(frame);
    }

    public static object ExitFrame(object f)
    {
      ((DispatcherFrame)f).Continue = false;

      return null;
    }
  }
}

Usage in code:

DoEvents.Do();

Better is to use somekind of (background) thread but for simple things this will do.