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

标签 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

异步有何好处?当然,在数据库搜索到记录之前,应用程序无法继续。

最佳答案

这是关于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/

相关文章:

c# - 查找在 Visual Studio 或单元测试中未使用 await 的异步用法

c# - 为什么 ASP.NET 的“记住我”功能如此健忘?

python - "yield from"语法在 asyncio 中有什么作用,它与 "await"有何不同

javascript - 并行与串行——如何使用异步按顺序执行函数

c# - 正则表达式在 .net 中不起作用

JavaScript 弹出窗口未触发?

asp.net-identity - Identity Server 4 API 上的声明为空

asp.net - 如何使用 Azure Active Directory 作为我的 Webform 和 MVC 应用程序的身份提供程序?

c# - 使用静态字典时,我在 ASP.NET 中收到错误 "Item has already been added."

javascript - 在 iFrame 中加载时 Asp.Net 页面抛出错误