title: WhenAll() not working as expected
body: <p>I need to make UI thread wait until a task array completes execution.The problem with below code is that - the tasks inturn invoke UI thread to write into textbox. How to fix this?</p>
  
  <pre><code>public partial class FormConsole : Form
  {
      public FormConsole()
      {
          InitializeComponent();
      }
      void txtSayHello_Click(object sender, EventArgs e)
      {
          Class1 objclss = new Class1();
          objclss.formConsole = this;
  
          Task[] taa = new Task[4];
          taa[0] = new Task(() =&gt; objclss.DoSomeThigs("Hello world"));
          taa[1] = new Task(() =&gt; objclss.DoSomeThigs("Hello world1"));
          taa[2] = new Task(() =&gt; objclss.DoSomeThigs("Hello world2"));
          taa[3] = new Task(() =&gt; objclss.DoSomeThigs("Hello world3"));
  
          foreach(Task task in taa)
          {
              task.Start();
          }
          Task.WhenAll(taa);
          this.txtConsole.AppendText("All threads complete");
      }
  
      delegate void doStuffDelegate(string value);
  
      public void doStuff(string value)
      {        
          if (System.Windows.Forms.Form.ActiveForm.InvokeRequired &amp;&amp; IsHandleCreated)
          {
              BeginInvoke(new doStuffDelegate(doStuff), value);        
          }
          else
              txtConsole.AppendText(value);        
      }
  
  }
  
  public class Class1
  {
      public FormConsole formConsole;
      public void DoSomeThigs(string sampleText)
      {
          formConsole.doStuff(sampleText);
      }
  }
  </code></pre>
  
  <p>o/p now : <code>Console Redirection TestAll threads completeHello worldHello world1Hello world2Hello world3</code></p>
  
  <p>o/p I want : <code>Console Redirection TestHello worldHello world1Hello world2Hello world3All threads complete</code></p>
  
  <p>What's the solution?</p>