static void AggregateExceptionsDemo() { var task1 = Task.Factory.StartNew(() => { var child1 = Task.Factory.StartNew(() => { throw new CustomException("Attached child2 faulted."); },TaskCreationOptions.AttachedToParent); throw new CustomException("Attached child1 faulted."); },TaskCreationOptions.AttachedToParent); try { task1.Wait(); } catch(AggregateException aes) { foreach(var e in aes.Flatten().InnerExceptions) { if(e is CustomException) { Console.WriteLine(e.Message); } } } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/77385.html
標籤:C#
