With below code Im trying to update customer model on cache & sql db asynchronously. Either one of the tasks or both tasks may fail & it will leads to AggregateException.
In the AggregateException I want to know which exception related to which task. Lets say inside AggregateException, I have Exception1 & Exception2. Want to know Exception1 originated by "updateCacheCustomerTask" failure while Exception2 originated by "updateDBCustomerTask" failure. How to do that? please suggest.
public async Task UpdateCustomerAsync(T model)
{
var updateCacheCustomerTask = Task.Run(() =>
{
throw new Exception();
});
var updateDBCustomerTask = Task.Run(() =>
{
throw new Exception();
});
await Task.WhenAll(updateCacheCustomerTask , updateDBCustomerTask ).ContinueWith(result =>
{
if (result.Exception != null)
{
throw result.Exception;
}
});
}