I'm a little confused for WaitAllu WaitAny. I try to get an exception, but when I do WaitAll, it returns an exception, but when use WaitAnyreturns nothing. And it is necessary that any of the completed work be carried out. They are any replacement WaitAny(). WaitAlland WhenAllthey are different from each other because I don’t want everything to be done. how
try
{
int i = 0;
Task t1 = Task.Factory.StartNew(() =>
{
i = 2 * 4;
});
Task<int> t2 = Task.Factory.StartNew(() =>
{
int a = 0;
int b = 100 / a;
return 0;
});
Task[] tasks = new Task[] { t1, t2 };
Task.WaitAny(tasks);
//Task.WaitAll(tasks);// Working
}
catch (AggregateException ae)
{
var message = ae.InnerException.Message;
Console.WriteLine(message);
}
Console.ReadLine();
source
share