http://www.hanselman.com/blog/TheMagicOfUsingAsynchronousMethodsInASPNET45PlusAnImportantGotcha.aspx
@Ben, @Daniel: You should not use Task.Run on the server side. It makes sense on the client (to free up the UI thread), but it does not make sense on the server side (you're freeing up a worker thread... by using another worker thread). This is covered in an excellent video on Channel9.
@Daniel: You should not use Task.Result in async code; it's easy to cause deadlocks.
@Ben: All three tasks are running when you call the first await, so even though that method is suspended, the other tasks are already running.
@MarcelWijnands: It's the difference between "wait for the first task, then continue the method, wait for the second task, then continue the method, wait for the third task, then continue the method" and "wait for all tasks, then continue the method". The Task.WhenAll approach has less switching back and forth.
Also from Stephen, never block on async code on a synchronous method (using Task.Wait()) like so
Figure 3 A Common Deadlock Problem When Blocking on Async Code
1.public static class DeadlockDemo
2.{
3. private static async Task DelayAsync()
4. {
5. await Task.Delay(1000);
6. }
7. // This method causes a deadlock when called in a GUI or ASP.NET context.
8. public static void Test()
9. {
10. // Start the delay.
11. var delayTask = DelayAsync();
12. // Wait for the delay to complete.
13. delayTask.Wait();
14. }
15.}
@Daniel: You should not use Task.Result in async code; it's easy to cause deadlocks.
@Ben: All three tasks are running when you call the first await, so even though that method is suspended, the other tasks are already running.
@MarcelWijnands: It's the difference between "wait for the first task, then continue the method, wait for the second task, then continue the method, wait for the third task, then continue the method" and "wait for all tasks, then continue the method". The Task.WhenAll approach has less switching back and forth.
Also from Stephen, never block on async code on a synchronous method (using Task.Wait()) like so
Figure 3 A Common Deadlock Problem When Blocking on Async Code
1.public static class DeadlockDemo
2.{
3. private static async Task DelayAsync()
4. {
5. await Task.Delay(1000);
6. }
7. // This method causes a deadlock when called in a GUI or ASP.NET context.
8. public static void Test()
9. {
10. // Start the delay.
11. var delayTask = DelayAsync();
12. // Wait for the delay to complete.
13. delayTask.Wait();
14. }
15.}