title: C# Multiple Tasks Blocked On Invoke Line
body: <p>I have a scenario where I create 3 Tasks:</p>
  
  <pre><code>List&lt;Task&gt; tasks = new List&lt;Task&gt;();
  tasks.Add(Task.Run(() =&gt; DoSomething("fu"));
  tasks.Add(Task.Run(() =&gt; DoSomething("man"));
  tasks.Add(Task.Run(() =&gt; DoSomething("chu"));
  Task.WaitAll(tasks.ToArray());
  </code></pre>
  
  <p>Each task simply passes its value to another method called Report() that tries to append text to a single textbox. Given the asynchronous scenario here, I check the InvokeRequired and also make use of a syncroot object.</p>
  
  <pre><code>private object syncRoot = new object();
  
  public void DoSomething (string x)
  {
      Report(x);
  }
  
  public void Report(string Message)
  {
      if (txtLog != null)
      {
          if (txtLog.InvokeRequired)
          {
              txtLog.Invoke(new MethodInvoker(() =&gt; Report(Message)));
          }
          else
          {
              lock (syncRoot)
              {
                  txtLog.AppendText(DateTime.Now.ToString("o") + " :: " + System.Threading.Thread.CurrentThread.ManagedThreadId + " :: " + Message.TrimEnd() + "\r\n");
              }
          }
      }
  }
  </code></pre>
  
  <p>Now, this Report() code seems to work fine in other scenarios (where there's 1 async task), but in this scenario, each of the 3 tasks gets to the txtLog.Invoke(...) line and then hangs. If I pause execution via the debugger, I can see all 3 are just sitting at that line and are flagged as Blocked. </p>
  
  <p>However, I'm not sure WHY that particular line would be blocked. Any ideas?</p>