await
关键字的目的是让你不用写难看的回调就可以使用asynchronous operations.
使用异步操作有助于避免浪费线程池线程.
Explanation
ASP.Net runs all of your code in threads from the managed thread pool.
If you have too many slow requests running at once, the thread pool will get full, and new requests will need to wait for a thread to get free.
然而,通常情况下,您的请求之所以慢,并不是因为它们正在进行计算(计算绑定),而是因为它们正在等待其他东西,例如硬盘、数据库服务器或外部Web服务(IO或网络绑定).
仅仅为了等待外部操作完成而浪费宝贵的线程池线程是没有意义的.
Asynchronous operations allow you to start the operation, return your thread to the pool, then "wake up" on a different thread pool thread when the operation is finished.
While the operation is running, no threads are consumed.