title: AutoResetEvent fire before signal
body: <p>I've two similar methods to below ones. In the <code>MainThreadDoWork</code> method the loop is finish executing regardless of the autoResetEvent.Set() in the <code>OtherThreadWork</code> method. Any idea what's happening in this AutoResetEvent instance?</p>
  
  <pre><code>AutoResetEvent autoResetEvent = new AutoResetEvent(true);
  private int count = 10;
  
  private void MainThreadDoWork(object sender, EventArgs e)
  {
      for (int i = 0; i &lt; count; i++)
      {
          if (autoResetEvent.WaitOne())
          {
              Console.WriteLine(i.ToString());
          }
      }
  }
  
  private void OtherThreadWork()
  {
      autoResetEvent.Set();
      //DoSomething();
  }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Below is how actual OtherThreadWork looks like.</p>
  
  <pre><code>  private void OtherThreadWork()
      {
          if (textbox.InvokeRequired)
          {
              this.textbox.BeginInvoke(new MethodInvoker(delegate() { OtherThreadWork(); }));
              autoResetEvent.Set();
          }
          else
          {
             // Some other code
          }
      }
  </code></pre>