title: c# Custom Threading Leak and WaitHandle.WaitAny()
body: <p>I have an application that seems to leak. One of of the Timers.Timer object stopped to elapse events and starts to leak threads as in <a href="https://stackoverflow.com/questions/26521689/net-4-0-system-timers-timer-seems-to-not-execute-the-elapsed-event-after-some-t">.NET 4.0 System.Timers.Timer seems to not execute the elapsed event after some time</a>. </p>
  
  <p>There are other threads and some just stopped to process and shows below stack trace. There are about 8 waiting threads in the <code>~*e !clrstack</code> </p>
  
  <pre><code>Child SP IP       Call Site
  07baf8f8 778f5cd4 [HelperMethodFrame_1OBJ: 07baf8f8] System.Threading.WaitHandle.WaitMultiple(System.Threading.WaitHandle[], Int32, Boolean, Boolean)
  07baf9c0 70d0dd2b System.Threading.WaitHandle.WaitAny(System.Threading.WaitHandle[], Int32, Boolean)
  07baf9e0 018a6129 MyDatabaseThread.threadMain()
  07bafa30 018a5eee &lt;Module&gt;.OS.UnmanagedThreadProc(Void*)
  </code></pre>
  
  <p>Below is some of the code snippets under threadMain()</p>
  
  <pre><code>WaitHandle[] waitHandles = new WaitHandle[2];
  waitHandles[0] = _threadAbort;
  WaitHandles[1] = _messageWaiting;
  WaitHandle.WaitAny(waitHandles);
  </code></pre>
  
  <p>the wait handles are declared as follows.</p>
  
  <pre><code>private AutoResetEvent _messageWaiting;
  private ManualResetEvent _threadAbort;
  </code></pre>
  
  <p>Any help would be appreciated. I cannot figure what is causing the hangup. Thanks</p>