title: UI thread not refreshing as expected into a WPF form
body: <p>I have an issue with UI refresh in this RelayCommand:</p>
  
  <pre><code>private RelayCommand _DeleteReferenceCommand;
  public RelayCommand DeleteReferenceCommand
  {
      get
      {
          return _DeleteReferenceCommand ?? (_DeleteReferenceCommand = new RelayCommand(
              () =&gt;
                {
                   //the 2 next lines trigger properties that will modify some components Visibility on the view
                   ReferencesGridWithPicsUC.TextReplacingGridView = "Deleting the reference. Please wait...";
                   ReferencesGridWithPicsUC.GridViewVisibility = false;
                  System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; // mouse cursor change
  
  
                 //using multi-threading so that UI updates while a long process takes place in the background
                 Task.Run(() =&gt;
                 {
                    Application.Current.Dispatcher.Invoke((new Action(() =&gt;
                    {
                      System.Threading.Thread.Sleep(3000); // simulates a long process
                      ReferencesGridWithPicsUC.GridViewVisibility = true; // Sets the UI controls visibility back to previous state
                      System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Hand; // Mouse cursor back to previous value
                   }
                )));
             }
         );
       },
       () =&gt; { return ReferencesGridWithPicsUC.SelectedReference != null; }
      ));
    }
  }
  </code></pre>
  
  <p>Concretely, when I start the app and run this code for the forst time, it works as expected (mouse cursor and controls are updated as expected before the Sleep(3000) and back to normal afterwards. When the code is executed again, I can see that the property is correctly updated GridViewVisibility . But the UI does not refresh anymore: the control visibility triggered by GridViewVisibility changes is not updated. On the other hand the mouse cursor keeps updating as expected....</p>
  
  <p>If someone can solve this bloody puzzle, I ll be in your debt ;)</p>