Created a new ASP.NET MVC project in Visual Studio 2013 (which is probably MVC 4)?
The default code / template / generated for the new project contains the account controller. There are async Task<ActionResult>Actions in this controller , but I don’t understand them, or why they are used by synchronous code.
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
return RedirectToAction("Index", "Home");
}
else
{
AddErrors(result);
}
}
return View(model);
}
What is the advantage of this async call? Why follow this pattern instead of making it a regular method ActionResult?
source
share