User1904516115 posted
How to handle exception with Parallel class for every iteration? I am using following code but "Handled" message is printing only 5 times
using System;
using System.Threading.Tasks;
namespace ThreadPooling
{
class Program
{
static void Main(string[] args)
{
try
{
Parallel.For(1, 10, i =>
{
int dividend = 0;
int result = i / dividend;
});
}
catch (AggregateException ex)
{
ex.Flatten().Handle(p =>
{
Console.WriteLine("Handled");
return true;
});
}
Console.ReadLine();
}
}
}