title: Asynchronous methods of ApiController -- what's the profit? When to use?
body: <p>(This probably duplicates the question <a href="https://stackoverflow.com/questions/15190112/asp-net-mvc4-async-controller-why-to-use">ASP.NET MVC4 Async controller - Why to use?</a>, but about webapi, and I do not agree with answers in there)</p>
  
  <p>Suppose I have a long running SQL request. Its data should be than serialized to JSON and sent to browser (as a response for xhr request). Sample code:</p>
  
  <pre><code>public class DataController : ApiController
  {
      public Task&lt;Data&gt; Get()
      {
          return LoadDataAsync(); // Load data asynchronously?
      }
  }
  </code></pre>
  
  <p>What actually happens when I do $.getJson('api/data', ...) (see this poster <a href="http://www.asp.net/posters/web-api/ASP.NET-Web-API-Poster.pdf" rel="nofollow noreferrer">http://www.asp.net/posters/web-api/ASP.NET-Web-API-Poster.pdf</a>):</p>
  
  <ol>
  <li>[IIS] Request is accepted by IIS.</li>
  <li>[IIS] IIS waits for one thread [THREAD] from the managed pool (<a href="http://msdn.microsoft.com/en-us/library/0ka9477y(v=vs.110).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/0ka9477y(v=vs.110).aspx</a>) and starts work in it.</li>
  <li>[THREAD] Webapi Creates new DataController object in that thread, and other classes.</li>
  <li>[THREAD] Uses task-parallel lib to start a sql-query in [THREAD2]</li>
  <li>[THREAD] goes back to managed pool, ready for other processing</li>
  <li>[THREAD2] works with sql driver, reads data as it ready and invokes [THREAD3] to reply for xhr request</li>
  <li>[THREAD3] sends response.</li>
  </ol>
  
  <p>Please, feel free to correct me, if there's something wrong.</p>
  
  <p>In the question above, they say, the point and profit is, that [THREAD2] is not from The Managed Pool, however MSDN article (link above) says that </p>
  
  <blockquote>
    <p>By default, parallel library types like <code>Task</code> and <code>Task&lt;TResult&gt;</code> use thread pool threads to run tasks.</p>
  </blockquote>
  
  <p>So I make a conclusion, that all THREE THREADS are from managed pool.</p>
  
  <p>Furthermore, if I used synchronous method, I would still keep my server responsive, using only one thread (from the precious thread pool).</p>
  
  <p>So, what's the actual point of swapping from 1 thread to 3 threads? Why not just maximize threads in thread pool?</p>
  
  <p>Are there any clearly useful ways of using async controllers?</p>