title: Perform a task after all UI tasks are done
body: <p>As written in the title, I'm trying to write a piece of code that executes after all UI tasks. I've tried to use the <code>Dispatcher</code> with no success, and ended up using a <code>BackgroundWorker</code> with <code>Thread.Sleep(1000)</code> which feels risky to me.</p>
  
  <p><strong>Code snippet - using BackgroundWorker:</strong></p>
  
  <pre><code>BackgroundWorker bw2 = new BackgroundWorker();
  bw2.DoWork += (o, e) =&gt; Thread.Sleep(1000);
  bw2.RunWorkerCompleted += (o, e) =&gt; MyMethod();
  bw2.RunWorkerAsync();
  </code></pre>
  
  <p><strong>Code snippet - using Dispatcher (which is not executed when I want it to):</strong></p>
  
  <pre><code>Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =&gt; MyMethod()));
  </code></pre>
  
  <p>I also tried to use <code>DispatcherPriority.Background</code></p>