title: What is a DispatcherFrame and how do I use it?
body: <p>Here's the code provided by <a href="https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherframe(v=vs.110).aspx" rel="noreferrer">MSDN</a>, although it doesn't appear to be clear on what it's doing:</p>
  
  <pre><code>[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  public void DoEvents()
  {
      DispatcherFrame frame = new DispatcherFrame();
      Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
      new DispatcherOperationCallback(ExitFrame), frame);
      Dispatcher.PushFrame(frame);
  }
  
  public object ExitFrame(object f)
  {
      ((DispatcherFrame)f).Continue = false;
  
      return null;
  }
  </code></pre>
  
  <p>I've just noticed a similar implementation in some legacy code today where the <code>DoEvents</code> method was defined. Why do we need this and what does it mean to push a frame onto the dispatcher?</p>