title: WPF DispatcherFrame magic - how and why this works?
body: <p>I was trying to animate some stuff in <code>WPF</code> and run some other operations when animation finishes.</p>
  
  <p>Also, wanted to avoid animation finish callback mechanism, so, I came up with a solution illustrated in the code below: </p>
  
  <pre><code>// Start one second of animation
  ...
  
  // Pause for one second
  Wait(this.Dispatcher, 1000);
  
  // Continue and do some other stuff
  ...
  </code></pre>
  
  <p>Now, the interesting part is <code>Wait</code> method which <strong>magically</strong> makes blocking pause in my code <strong>but</strong> the animation and UI stays normal, responsive:</p>
  
  <pre><code>    public static void Wait(Dispatcher Dispatcher, int Milliseconds)
      {
          var Frame = new DispatcherFrame();
          ThreadPool.QueueUserWorkItem(State =&gt;
          {
              Thread.Sleep(Milliseconds);
              Frame.Continue = false;
          });
          Dispatcher.PushFrame(Frame);
      }
  </code></pre>
  
  <p>I have read a documentation and a few articles about <code>DispatcherFrame</code> but I am still unable to figure out what is really happening under the hood, and I need some clarification about how this construction with <code>PushFrame</code> really works.</p>