title: UI not updating buttons when using Task.Factory.StartNew in WPF C#
body: <p>WPF/XAML/C# I set visibility of progress bar to visible, then hidden after a long running process.  I am trying to use Task.Factory.StartNew and ContinueWith to accomplish this.  This part works fine, but for some reaso, my navigation buttons that are databound to commands do not update until i actually click the screen following the long process.  if i omit the task.factory.startnew, the buttons update correctly (but i never see the progress bar).  how do i fix this?  Here's sample code showing problem with the process and buttons not updating in the UI:</p>
  
  <pre><code>private void DoWorkCommandExecuted()
          {
              //Do stuff
              ShowProgress = Visibility.Visible;
  
              Task.Factory.StartNew(() =&gt;
                  {
                      //Thread.Sleep(3000);
                      for (int i = 0; i &lt; 10000; i++)
                      {
                          s += i.ToString();
                      }
  
                      ObservableCollection&lt;string&gt; temp = new ObservableCollection&lt;string&gt;();
                      temp.Add("One");
                      temp.Add("Two");
                      temp.Add("Three");
                      temp.Add("Four");
                      temp.Add("Five");
  
                      BillingCycles = temp;
  
                      SelectedBillingCycle = BillingCycles[0];
                  })
                  .ContinueWith(t =&gt;
              {
                  ShowProgress = Visibility.Hidden;
              });
          }
  </code></pre>
  
  <p>And a sample of one the property the buttons code that controls it enabled :</p>
  
  <pre><code>private bool CanFirst
          {
              get
              {
                  bool b = false;
  
                  if (BillingCycles != null)
                  {
                      if (BillingCycles.Count &gt; 0 &amp;&amp; SelectedBillingCycle != BillingCycles[BillingCycles.Count - 1])
                      {
                          b = true;
                      }
                  }
  
                  return b;
              }
          }
  </code></pre>
  
  <p>I am using INotifyPropertyChanged.  This is a very basic example illustrating my problem, which is in a much more complex program.  The "Go to first" or "Go to last" buttons should enable/disable based on what BillingCycle is selected.  If i do not include the code to run in thread, the buttons are enabled/disabled correctly (i just can't see the progress bar while the process happens).</p>