I have seen an example of AggregateException
on the web and I'm trying to figure out how it works. I have written a simple example, but my code for some reason doesn't work.
Could someone explain to me what the problem is?
public static void Main()
{
try
{
Parallel.For(0, 500000, i =>
{
if (i == 10523)
throw new TimeoutException("i = 10523");
Console.WriteLine(i + "
");
});
}
catch (AggregateException exception)
{
foreach (Exception ex in exception.InnerExceptions)
{
Console.WriteLine(ex.ToString());
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…