Explanation of asynchronous actions from a new default ASP.NET MVC project?

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);
        }
    }

    // If we got this far, something failed, redisplay form
    return View(model);
}

What is the advantage of this async call? Why follow this pattern instead of making it a regular method ActionResult?

+4
source share
1 answer

The answer is more efficient use of resources .

, , , . , , .

, ( -). async ; .

async:

  • , , .NET 4.5 .
  • I/O .
  • Parallelism , .
  • , .
  • . , , ASP.NET . , ASP.NET , , -.
  • , IIS , .

async:

  • .
  • .
  • - , , . .

: ASP.NET 4.5

0

All Articles