Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 769
Sam Avatar asked May 07 '14 18:05

Sam


1 Answers

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.

like image 120
Erik Elkins Avatar answered Nov 13 '22 21:11

Erik Elkins