Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有三个任务,我在启动三个任务后调用了 Task.WaitAll(task1,task2,task3)。
该程序在调试模式下运行良好。当它切换到释放模式时,会抛出 AggregateException。
我想知道如何找到异常的原因。
谢谢
您可以捕获异常,然后打印出每个内部异常,如下所示:
try { Task.WaitAll(task1, task2, task3); } catch (AggregateException ex) { foreach (Exception exx in ex.Flatten().InnerExceptions) Console.WriteLine(exx.Message); }