Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Handle all AggregateExceptions when using Task.Whenall() async

Task aggregationTask = null;
try{
  var task1 = DoSomethingAsync();
  var task2 = DoSomethingElseAsync();
  aggregationTask = Task.WhenAll(task1, task2);
  await aggregationTask;
}catch(Exception ex){  
  if(aggregationTask?.Exception?.InnerExceptions != null && aggregationTask.Exception.InnerExceptions.Any())
    foreach (var innerEx in aggregationTask.Exception.InnerExceptions){
      // do your magic here
    }
}
Source by gist.githubusercontent.com #
 
PREVIOUS NEXT
Tagged: #Handle #AggregateExceptions #async
ADD COMMENT
Topic
Name
5+4 =