Created a new ASP.NET MVC project in Visual Studio 2013 (which is MVC 4 I guess?)
The default/template/generated code for the new project contains an Account controller. In that controller are async Task<ActionResult>
Actions, but I don't really understand them, or why they are being used over syncrhonous 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);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
What is the benefit of making this call async? Why follow this pattern instead of making it a regular ActionResult
method?