While perusing the AccountController code created by Visual Studio 2013. I see a pattern of sequential calls to async methods with each call performing await.
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl){
if (User.Identity.IsAuthenticated){
return RedirectToAction("Manage");
}
if (ModelState.IsValid){
// Get the information about the user from the external login provider
var info = await AuthenticationManager.GetExternalLoginInfoAsync();
if (info == null){
return View("ExternalLoginFailure");
}
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user);
if (result.Succeeded){
result = await UserManager.AddLoginAsync(user.Id, info.Login);
if (result.Succeeded){
await SignInAsync(user, isPersistent: false);
return RedirectToLocal(returnUrl);
}
}
AddErrors(result);
}
ViewBag.ReturnUrl = returnUrl;
return View(model);
}
Is there some advantage to this await-async pattern that I am not seeing? The await operators make these blocking calls which makes them basically old fashioned synchronous calls.
Answer
I can't yet answer my own question due to lack of reputation but I found the answer here, while I did search prior to posting, I missed it. The calls are blocking, what I missed, and is not at all clear in the documentation, is that ASP.NET is returning the current worker thread back to the ASP.NET thread pool during the blocking.
Further Reading TAP (Task based Asynchronous Pattern) is the new pattern asynchrony in the .NET Framework. Here is link to more info on the pattern than most will want to digest.