title: How to force a UI update during a lengthy task on the UI thread
body: <p>I have a window, and the window contains it's content and a "Loading" overlay as follows</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;Grid&gt;
          &lt;!-- STUFF --&gt;
      &lt;/Grid&gt;
      &lt;Rectangle Fill="White" Opacity="0.7" Visibility="{Binding VisibilityWait, Mode=TwoWay, 
      Converter={StaticResource BoolToVisibilityConverter}}" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>My ViewModel then implements INotifyPropertyChanged and includes the property;</p>
  
  <pre><code>    private bool visibilityWait;
      public bool VisibilityWait
      {
          get
          {
              return visibilityWait;
          }
          set
          {
              visibilityWait = value;
              OnPropertyChanged("VisibilityWait");
          }
      }
  </code></pre>
  
  <p>I know that this is set up correctly because if I set the VisibilityWait to true in the constructor, the window displays with the "Loading" overlay as expected and vice versa... However, if i try to do this during a method e.g.;</p>
  
  <pre><code>private void someMethod()
  {
      VisibilityWait = true;
      //... Do things
      VisibilityWait = false;
  }
  </code></pre>
  
  <p>Then during the time that the program is in the "do things" section, the UI does not update to show the loading overlay.</p>
  
  <p>How do I solve this issue?</p>
  
  <p>EDIT: I found my own solution to this problem. See the answer below.</p>