await 非 async方法

Task.whenall()不是异步方法,为什么await task.whenall() 可以工作?

http://blog.stephencleary.com/2012/02/async-and-await.html

One important point about awaitables is this: it is the type that is awaitable, not the method returning the type. In other words, you can await the result of an async method that returns Task … because the method returns Task, not because it’s async. So you can also await the result of a non-async method that returns Task

Task类最重要的方法就是GetAwaiter.

碰到await关键字,CompilerService会编译出taskBuilder,async state machine等隐藏的类代码(要看IL+c#) 并使用awaiter的各种方法(比如GetResult())