title: Replacing a While loop with AutoResetEvent for blocking a thread
body: <p>Recently, I was finally able to make a separate thread work. Now I am trying to master synchronization.</p>
  
  <p>As far as I know, pausing a thread with <code>ThreadName.Suspend()</code> is not a good idea. At fist I used a <code>While</code> loop to block the thread. Later I noticed that this consumes resources, so now I am trying to replace the loop with an <code>AutoResetEvent</code>.</p>
  
  <p>Here is some code (tell me if you the full code):</p>
  
  <pre><code>private void combTester(object sender, EventArgs e)//happens in a timer, because it manipulates the GUI
  {
      if (!timer2Block)
      {
          //stuff happens
          genBlock = false;//unblocks the thread
          timer2Block = true;//blocks itself
          //debugging stuff happens
      }
      if (done)
          timer2.Enabled = false;
  }
  
  private void combGenerator(int currEl, int begVal)
  {
      //setting a variable
      for (int c = begVal; c &lt;= currEl + totalCells - maxCells; c++)
      {
          while (genBlock &amp;&amp; !abortTime)
          {
              if (abortTime)
                  return;
          }
          genBlock = true;//blocks itself
          //some recursive stuff happens,
          //because of which I was forced to use a thread instead of timers
      }
  }
  </code></pre>
  
  <p>I tried different places to put the <code>Wait()</code> and <code>Set()</code> methods, but both the tread and the timer get blocked and I don't know how to debug the program.</p>
  
  <p>So, how can I replace the <code>While</code> loop with <code>AutoResetEvent</code>?</p>