title: How do I use WaitHandles safely to prevent deadlocks?
body: <p>Observe the following pseudo:</p>
  
  <pre><code>ManualResetEvent[] resetEvents = new ManualResetEvent[operations.Count];
  
  for( int i = 0; i &lt; operations.Count; i++ )
  {
    resetEvents[i] = new ManualResetEvent(false);
    ThreadPool.QueueUserWorkItem(new WaitCallback(timeConsumingOpHandler), resetEvents[i]);
  }
  
  WaitHandle.WaitAll(resetEvents);
  </code></pre>
  
  <p>In the case that an exception occurs inside one of the pooled threads, my ASP.NET WebApp is deadlocking.  No exception information is being passed on the response stream.
  I'm seeking suggestions to prevent this.  A fixed timeout is acceptable.
  Assume that the timeConsumingOpHandler Set()s the WaitHandle.</p>
  
  <p>The entire timeConsumingOpHandler is wrapped in a try-catch-finally block where the WaitHandle is Set() during the finally section.  None the less, deadlock occurs.</p>