Exemple #1
0
 private void RunTaskExceptionHandling3()
 {
     try
     {
         Console.WriteLine("taskWithException started");
         SimpleAsyncClass2 SAC2 = new SimpleAsyncClass2();
         Task failedTask        = SAC2.TaskMethodThatWillFail();
         failedTask.Wait();
         Console.WriteLine("taskWithException complete");
     }
     catch (AggregateException e)
     {
         Console.WriteLine("AggregateException: " + e.InnerException.Message);
     }
 }
Exemple #2
0
        private void RunMultiTaskExceptionHandling()
        {
            try
            {
                Console.WriteLine("Multi Task Exception started");
                SimpleAsyncClass2 SAC2 = new SimpleAsyncClass2();

                Task failedTask     = SAC2.TaskMethodThatWillFail();
                Task failedTask2    = SAC2.TaskMethodThatWillFail2();
                Task successfulTask = SAC2.AsyncMethod1();

                Task[] taskArray = { failedTask, failedTask2, successfulTask };
                Task.WaitAll(taskArray);

                Console.WriteLine("Multi Task Exception complete");
            }
            catch (AggregateException e)
            {
                foreach (Exception ex in e.InnerExceptions)
                {
                    Console.WriteLine("Tasking Error: " + ex.Message);
                }
            }
        }