title: Async calls in Web Api
body: <p>In asp.net Web API how can I call long running blocking actions asynchronously?</p>
  
  <p>I have a web api controller action that needs to make a relatively (10 seconds, as an example) long running DB call. This seems like a candidate for an asynchronous method. I can offload the long running task onto a new thread, and unblock my asp.net request thread to handle some other requests, so my simplified controller action would look like this:</p>
  
  <pre><code>public async Task&lt;IHttpActionResult&gt; Get()
  {
      IEnumerable&lt;Thing&gt; things = await Task.Run(() =&gt; DoLongDbCall());
      return Ok(things);
  }
  </code></pre>
  
  <p>I have encountered a couple of blogs (<a href="http://blog.stephencleary.com/2013/11/taskrun-etiquette-examples-dont-use.html" rel="nofollow">this one</a>, for example) that suggest this may not be an optimal way to achieve this in asp.net. The author suggests using <code>Task.FromResult()</code> and doing the DB call synchronously, but i cant see how this helps; My request thread is still going to be blocked waiting for the DB call to return. </p>