title: Asynchronous Multithreading Exception Handling?
body: <p>I want to have an exception handling approach in my Asynchronous programming (beginInvoke/endInvoke) wherein if any one of the thread(beginInvoke) fails, then I want all other asynchrounous processing thread to stop working. Please suggest some solution?, below I am attaching my sample code also:</p>
  
  <pre><code>public List&lt;ThreadResultDto&gt; SendMailAsynch(List&lt;ThreadRequestDto&gt;  requestDto)
  {
      List&lt;ThreadResultDto&gt; resultDto = new List&lt;ThreadResultDto&gt;();
      List&lt;IAsyncResult&gt; asyncResults = new List&lt;IAsyncResult&gt;();
  
      foreach (ThreadRequestDto t in requestDto)
      {
          //Create a delegate.
          DoSomeAsynchWorkDelegate del = new DoSomeAsynchWorkDelegate(DoSomeAsynchWork);
          // Initiate the asynchronous call
          IAsyncResult a = del.BeginInvoke(t,null, del);
          //IAsyncResult a = del.BeginInvoke(t, null,null);
          asyncResults.Add(a);
      }
  
      foreach (IAsyncResult ar in asyncResults)
      {
          // wait for each one to complete, then call EndInvoke, passing in the IAsyncResult.
          // We cast ar.AsyncState to a DoSomeAsynchWorkDelegate, as we passed it in as the second parameter to BeginInvoke. 
          ar.AsyncWaitHandle.WaitOne();
  
          //AsyncState property of IAsyncResult is used to get the delegate that was used to call that method
          DoSomeAsynchWorkDelegate del = (DoSomeAsynchWorkDelegate)ar.AsyncState;
  
          // Call EndInvoke to get the result.  Add the result to the list of items. 
          resultDto.Add(del.EndInvoke(ar));
      }
  
      return resultDto;
  }
  </code></pre>