In the following code task1 and task2 are independent of each other and can run in parallel. What is the difference between following two implementations?
var task1 = GetList1Async(); var task2 = GetList2Async(); await Task.WhenAll(task1, task2); var result1 = await task1; var result2 = await task2; and
var task1 = GetList1Async(); var task2 = GetList2Async(); var result1 = await task1; var result2 = await task2; Why should I choose one over the other?
Edit: I would like to add that return type of GetList1Async() and GetList2Async() methods are different.
var result = await task1;would be the exact same ofvar result = task1.Result. I do think that.Resultis more readable though.AggregateException) than when usingawait(the first exception), so when usingasync/awaityou should prefer usingawaitover.Resultto keep exception behavior consistent.