title: Async and Await in ApiController Post
body: <p>I'm still not quite clear about async and await in .net 4.5. So far, I think I understand that await:</p>
  
  <ol>
  <li>puts the function (to its right) on a separate thread.</li>
  <li>puts the execution back to the current function's caller</li>
  <li>but holds the rest of the current function's code "hostage" until the awaiting (async) function is finished.</li>
  </ol>
  
  <p>Please correct me if I'm misunderstanding something. So, if the above is true, I'm stuck with an ApiController's Post function that I want async:</p>
  
  <pre><code>[HttpPost]
  public async Task&lt;HttpResponseMessage&gt; Post([FromBody]MyObject obj)
  {        
       myDataContext.MyObjects.InsertOnSubmit(obj);
       myDataContext.SubmitChanges();
  
       await SomeReallyLongRunningTaskAsync();        
  
       // obj would now have the new Id, which I'm really after.
       return Request.CreateResponse(HttpStatusCode.Created, obj);
  
  }
  </code></pre>
  
  <p>So if I'm understanding this correctly, Post will finish execution and return control to whoever called <code>myApiController.Post(obj)</code>. But I don't have the <code>HttpResponseMessage</code> object yet since await held <code>return Request.CreateResponse(HttpStatusCode.Created, obj);</code> "hostage".</p>
  
  <p>In this above simple example, would the call immediately return to the client (that is, client JS website or mobile app)? If so, would it be a 201, 400, 500 (better not), others?</p>