Exception handling in multithreaded C#

try
{
  Parallel.Invoke(
    () =>
    {
      Console.WriteLine("Starting Job 1..");
      Thread.Sleep(3*1000);
      Console.WriteLine("Starting Job 1.. SUCCESS");
    },
    () =>
    {
      Console.WriteLine("Starting Job 2..");
      throw new Exception("Job 2 Failed");
    }
  );
}
catch (AggregateException ex)
{
  Console.WriteLine(ex);
  foreach (var innerEx in ex.InnerExceptions)
  {
    Console.WriteLine(innerEx);
  }        
}

Comments

  1. Neither life nor playing presents any guarantees, and your precise day by day results may be be} far totally different than your theoretical loss, so plan accordingly. Freshen up your ground, interact players and drive growth with IGT Fruit Games. QuikTicket™ is an enhanced way to play Slots, the place have the 카지노 사이트 ability to|you possibly can} entry your cash without debit account day by day withdrawal limits.

    ReplyDelete

Post a Comment

Popular posts from this blog

Parse XML to dynamic object in C#

C# Updating GUI from different thread