title: How to make ASP.NET MVC Controller Methods Async
body: <p>I'm launching multiple ajax calls to various MVC controllers to load different parts of my page. However it seems that when this gets to the controller only one runs at a time. I'm guessing this is because by default ASP.Net MVC controllers are synchronous? I've also tested loading a page on 2 browser tabs and the second tab always waits for the first.</p>
  
  <p>To get round this I've attempted to make the controller methods in question asynchronous.  I've done this by doing the following</p>
  
  <ol>
  <li>Append Async to controller method name</li>
  <li>Make the controller methods return async Task</li>
  <li>Used the Task.Factory.StartNew method to do the body of work in the method in a separate thread.</li>
  </ol>
  
  <p>For example the controller methods in question now look like this...</p>
  
  <pre><code>    public async Task&lt;JsonResult&gt; GetUser(int userId)
      {
          var result = await Task.Factory.StartNew(() =&gt; Task.Run(() =&gt;
          {                
              return userService.GetUser(userId);
          })).Result;
          return new JsonResult()
          {
              Data = result,
              JsonRequestBehavior = JsonRequestBehavior.AllowGet
          };
      } 
  </code></pre>
  
  <p>However it still seems to be synchronous. Am I missing something or going about this completely the wrong way? I've not really used the Task Library much so may be missing something big?</p>