title: Showing a WPF loading message until after UI finishes updating
body: <p>In my application, I'm allowing the user to select an item from a tree of items in the left side, and when that item gets selected, I should update the UI on the right side. Now, during the update of the UI (which might take a second or two), I display a "Please Wait" message to indicate that the application is currently working via a background thread.</p>
  
  <p>When the loading of the UI is completed I wish to make this "Please Wait" window disappear, but the problem now is that the data fetching process ends quite fast, which makes the "Please Wait" window to disappear, but since the UI hasn't yet updated, the app gets stuck for a second and then, only after UI was updated, it gets released.</p>
  
  <p>How can I send a message to remove the "Please Wait" message window only <strong>after</strong> UI has completed its work and refreshed? (I use GalaSoft's <code>Messenger</code> class to send messages through my application)</p>
  
  <p><strong>EDIT:</strong>
  This is my code for reference:</p>
  
  <pre><code>// Show the "Please wait window" while running the long operation
  var t = Task.Factory.StartNew(() =&gt; LoadingHelper.ShowProgressBar());
  
  t.ContinueWith((priorTask) =&gt;
                      {
                          // DOING SOME HEAVY LIFTING WORK HERE
  
                          // TRYING TO FORCE THE UI TO REFRESH
                          Application.Current.Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =&gt; { }));
                      });
  t.ContinueWith((antecedent) =&gt; LoadingHelper.HideProgressBar()); // Make the loading window disappear
  </code></pre>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>I'm aware of async programming. My question was mainly since my "heavy lifting" work is done and the "please wait" message is removed, but the UI is refreshing to reflect the results from the heavy work and that is taking a few moments. I want to keep the "Please Wait" message on the screen until all UI has done loading (maybe by using the <code>Loaded</code> event on the control?)</p>