title: AutoResetEvent clarification
body: <p>I want to clarify how the following code works.I have itemized my doubts to get your reply.</p>
  
  <pre><code>class AutoResetEventDemo
  {
      static AutoResetEvent autoEvent = new AutoResetEvent(false);
  
      static void Main()
      {
          Console.WriteLine("...Main starting...");
  
          ThreadPool.QueueUserWorkItem
          (new WaitCallback(CodingInCSharp), autoEvent);
  
          if(autoEvent.WaitOne(1000, false))
          {
              Console.WriteLine("Coding singalled(coding finished)");
          }
          else
          {
              Console.WriteLine("Timed out waiting for coding"); 
          }
  
          Console.WriteLine("..Main ending...");
  
          Console.ReadKey(true);
      }
  
      static void CodingInCSharp(object stateInfo) 
      {
          Console.WriteLine("Coding Begins.");
          Thread.Sleep(new Random().Next(100, 2000));
          Console.WriteLine("Coding Over");
         ((AutoResetEvent)stateInfo).Set();
      }
  }
  </code></pre>
  
  <ol>
  <li><p><code>static AutoResetEvent autoEvent = new AutoResetEvent(false);</code></p>
  
  <p>At initial stage signal is set to false.</p></li>
  <li><p><code>ThreadPool.QueueUserWorkItem(new WaitCallback(CodingInCSharp), autoEvent);</code></p>
  
  <p>Select a thread from ThreadPool and make that thread to execute CodingInCSharp.
     The purpose of WaitCallback is to execute the method after Main() thread
     finishes its execution.</p></li>
  <li><p><code>autoEvent.WaitOne(1000,false)</code></p>
  
  <p>Wait for 1 sec to get the signal from "CodingInCSharp")
  Incase if i use WaitOne(1000,<strong>true</strong>), will it kill the thread it received from
  threadpool?</p></li>
  <li><p>If I did not set <code>((AutoResetEvent)stateInfo).Set();</code> will the Main() indefinitely wait for signal?</p></li>
  </ol>