I understand that calling
Task<int> t1 = m1Async();
Task<int> t2 = m2Async();
await Task.WhenAll(t1, t2);
int result1 = t1.Result;
int result2 = t2.Result;
int result1 = await t1;
int result2 = await t2;
There's nothing inherently wrong or bad about using
t1.Result after you've already done an
await, but you may be opening yourself up to future issues. What if someone changes the code at the beginning of your method so you can no longer be positive the Tasks have completed successfully? And what if they don't see your code further down that makes this assumption?
Seems to me that it might be better to use the returned value from your first
Task<int> t1 = m1Async(); Task<int> t2 = m2Async(); var results = await Task.WhenAll(t1, t2); int result1 = results; int result2 = results;
That way, if someone messes with the first
await, there's a natural connection for them to follow to know that your code later is dependent on its result.
You may also want to consider whether
Task.WhenAll() is really giving you any value here. Unless you're hoping to tell the difference between one task failing and both failing, it might just be simple to await the tasks individually.
Task<int> t1 = m1Async(); Task<int> t2 = m2Async(); int result1 = await t1; int result2 = await t2;