8

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?

1

1 Answer 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...

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.