title: Return immediate response from async ApiController
body: <p>I've got a problem with returning an "immediate" response from an normally async ApiController.  The code is below, looks for the exclamation points.  The use-case is a content-type check fails and I want to send an error response message back. The first version hangs Visual Studion 2010 (and Fiddler).  The second works.</p>
  
  <p>My question is, why can't I use my initial approach of returning the dummy Task that merely passes back the response object?</p>
  
  <pre><code>public class MyController : ApiController
  {
  
     public Task&lt;HttpResponseMessage&gt; Post([FromUri]string arg)
     {
         HttpResponseMessage response = null;
  
         // synchronous validation
         if (Request.Content.Headers.ContentType.MediaType != @"image/jpeg")
         {                    
             response = Request.CreateErrorResponse(
                 HttpStatusCode.UnsupportedMediaType,
                 "Invalid Content-Type.");
         }
  
  
         if (response == null)  // no immediate response, switch to async
         {
            // work done here    
         }
         else // immediate response, but we need to wrap in a task for caller to fetch
         {
  
             // !!!! this one doesn't work !!!
             return new Task&lt;HttpResponseMessage&gt;( () =&gt; response);
  
             // !!! this one does !!!
             TaskCompletionSource&lt;HttpResponseMessage&gt; tcs = new TaskCompletionSource&lt;HttpResponseMessage&gt;();
             tcs.SetResult(response); 
             return tcs.Task;
  
         }
      }
  }
  </code></pre>