title: Problem with Invoke to parallelize foreach
body: <p>I have a problem with using System.Threading.Tasks.Parallel.ForEach. The body foreach progressBar want to update.
  But Invoke method sometimes freeze.</p>
  
  <p>I attach the code to the form which is prograssbar and Buton.</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      DateTime start = DateTime.Now;
      pforeach();
      Text = (DateTime.Now - start).ToString();
  }
  
  
  private void pforeach()
  {
      int[] intArray = new int[60];
      int totalcount = intArray.Length;
      object lck = new object();
      System.Threading.Tasks.Parallel.ForEach&lt;int, int&gt;(intArray,
      () =&gt; 0,
      (x, loop, count) =&gt;
      {
          int value = 0;
          System.Threading.Thread.Sleep(100);
          count++;
          value = (int)(100f / (float)totalcount * (float)count);
  
          Set(value);
          return count;
      },
      (x) =&gt;
      {
  
      });
  }
  
  private void Set(int i)
  {
      if (this.InvokeRequired)
      {
          var result = Invoke(new Action&lt;int&gt;(Set), i);
      }
      else
          progressBar1.Value = i;
  }
  </code></pre>
  
  <p>Sometimes it passes without a problem, but usually it freeze on 
  <code>var result = Invoke (new Action &lt;int&gt; (Set), i)</code>.
  Try to kick me in the problem.</p>
  
  <p>Thank you.</p>