為什么默認的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