Given the following:
var tPass1 = Task.FromResult(1);
var tFail1 = Task.FromException<int>(new ArgumentException("fail1"));
var tFail2 = Task.FromException<int>(new ArgumentException("fail2"));
var task = Task.WhenAll(tPass1, tFail1, tFail2);
task.Wait();
the call to task.Wait() throws an AggregateException
, whose inner exceptions contain the fail1
and fail2
exceptions. But how can I access the tPass1
successful result?
Is this possible?
I'm aware that I can get the result from the individual task after the WhenAll
has finished, via tPass1.Result
however is there a way to get them in an array to avoid having to manually track all the things feeding into the WhenAll
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…