为什么asp.net Identity api中的所有数据库访问方法都标记为异步

Age*_*eis 3 asp.net async-await asp.net-identity

考虑这个简单的伪代码

User logs in 
 Application access database to try retrieve the login using provided password and username
if record is found then show requested page otherwise display login with error message
Run Code Online (Sandbox Code Playgroud)

这如何从异步中获益?当然,在数据库搜索记录之前,应用程序无法继续.

tra*_*max 6

这是一个更普遍的问题async-await.以这种方式执行的方法不会阻塞执行线程,并且应用程序可用于执行其他工作,而DB将返回结果.这意味着您的应用程序可以在等待DB返回结果时提供其他请求(可能来自其他用户).

有很多关于async-await.你可以从这里开始:http://blogs.msdn.com/b/cdndevs/archive/2013/12/18/c-async-and-await-why-do-we-need-them-part-1. ASPX

并且,FYI,Identity库具有作为扩展方法提供的非异步方法.因此,如果您的应用程序是非异步的,那么您不必在应用程序中一直使用async关键字.