考虑这个简单的伪代码
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
异步有何好处?当然,在数据库搜索到记录之前,应用程序无法继续。
最佳答案
这是关于async-await
的更普遍的问题。以这种方式执行的方法不会阻塞执行线程,并且应用程序可以执行其他工作,同时 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
并且,仅供引用,身份库具有作为扩展方法提供的非异步方法。因此,如果您的应用程序是非异步的,则不必在整个应用程序中始终使用 async
关键字。
关于asp.net - 为什么 asp.net Identity api 中的所有数据库访问方法都标记为异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24595259/