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.

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?

有帮助吗?

解决方案

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

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.

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top