2

What is the difference between async Task<> and without it? Does it make a difference, and is this like using jquery ajax?

   [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> SetPassword(SetPasswordViewModel model)
    {

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

vs.

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult SetPassword(SetPasswordViewModel model)
    {

        // If we got this far, something failed, redisplay form
        return View(model);
    }
user1929393
  • 4,089
  • 7
  • 30
  • 48
  • well in the end they should not differ very much, because you are missing the `await` keyword. So there is no async at all. Related: http://stackoverflow.com/questions/26184247/async-vs-sync-benchmarks-on-mvc-controller-with-questions – Marco Jan 15 '15 at 08:27

1 Answers1

4

Async controller methods are beneficial for methods that are long running. For example, methods that are making expensive database queries or back-end service calls.

It is different than ajax. This causes your controller methods to execute in a new thread which frees up threads for the web server to process requests.

I know that's not the best description, but you can find more here:

http://msdn.microsoft.com/en-us/library/ee728598%28v=vs.100%29.aspx

Michael Dowd
  • 221
  • 1
  • 5