title: How to update UI from child tasks in WinForms
body: <p>I've got a simple little winforms app that performs a long running process on another thread via a TPL Task.  During this long running process I'd like to update the UI (the progress bar or something).  Is there a way to do this without being required to .ContinueWith()?</p>
  
  <pre><code>public partial class Form1 : Form
  {
      private Task _childTask;
  
      public Form1()
      {
          InitializeComponent();
  
          Task.Factory.StartNew(() =&gt;
          {
              // Do some work
              Thread.Sleep(1000);
  
              // Update the UI
              _childTask.Start();
  
              // Do more work
              Thread.Sleep(1000);
          });
  
          _childTask = new Task((antecedent) =&gt;
          {
              Thread.Sleep(2000);
              textBox1.Text = "From child task";
          }, TaskScheduler.FromCurrentSynchronizationContext());
  
  
      }
  }
  </code></pre>
  
  <p>Executing this code I get the ubiquitous exception: </p>
  
  <blockquote>
    <p>Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on. </p>
  </blockquote>