C# aggregateexception flatten innerexceptions

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);
                    }
                }
            }
        }

C# aggregateexception flatten innerexceptions

上一篇:解决win10系统文件名太长无法删除的问题


下一篇:# [0CTF 2016]piapiapia解题详细思路及复现