为什么默认的MVC站点使用异步ASP.net身份?

[英]Why does default MVC site use async ASP.net Identity?


I'm just curious why the ASP.net MVC website template uses the asynchronous methods for ASP.net Identity? They don't seem to be doing anything that would benefit from using asynchronous methods.

我只是好奇为什么ASP.net MVC网站模板使用ASP.net身份的异步方法?它们似乎没有做任何可以从使用异步方法中受益的东西。

For example, why use:

例如,为什么使用:

IdentityResult result = 
    await UserManager.RemoveLoginAsync(User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey));

Instead of:

代替:

IdentityResult result = 
    UserManager.RemoveLogin(User.Identity.GetUserId(), new UserLoginInfo(loginProvider, providerKey));

Aren't they doing the exact same thing? In both instances you are waiting for the IdentityResult before proceeding to the next line of code, correct?

他们不是在做同样的事情吗?在这两个实例中,您在继续下一行代码之前都在等待IdentityResult,对吗?

1 个解决方案

#1


7  

Correct, you are waiting for the RemoveLoginAsync to return before you execute the next line of code. However, there is benefit to doing this...

正确的是,在执行下一行代码之前,您正在等待RemoveLoginAsync返回。但是,这样做有好处......

While the RemoveLoginAsync is executing, it won't lock the thread (because it's async). So with the second example for instance, if you have 4 threads available for your app, and 4 requests come in, all waiting on a synchronous call, then additional requests will enter a queue before they can be processed.

当RemoveLoginAsync正在执行时,它不会锁定线程(因为它是异步的)。因此,对于第二个示例,如果您的应用程序有4个可用线程,并且有4个请求进入,所有等待同步调用,则其他请求将进入队列,然后才能进行处理。

But if you have an async call while waiting, then it frees up that thread to process more requests.

但是如果你在等待时有异步调用,那么它释放该线程来处理更多请求。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/05/07/19264b5f33921f5a45b1d1f909d151f6.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com