title: How should a DelegatingHandler make an async call (ASP.NET MVC Web API)?
body: <p>I am comfortable with executing synchonous work before calling the inner handler's SendAsync(), and executing synchronous work after the inner handler has completed via a completion. e.g:</p>
  
  <pre><code>protected override Task&lt;HttpResponseMessage&gt; SendAsync( 
      HttpRequestMessage request, CancellationToken cancellationToken) 
  { 
      // do some sync work before inner handler here 
  
      var sendTask = base.SendAsync(request, cancellationToken); 
      return sendTask.ContinueWith( 
          task =&gt; { // do some sync work afterwards here }); 
  } 
  </code></pre>
  
  <p>However, I now need to call an IO bound operation from within a delegating handler. The IO bound operation is already wrapped up as a <code>Task&lt;bool&gt;</code>. I need to use the result to determine whether to continue on to the inner handler.</p>
  
  <p>An example would be making a network call to authorize a request. I have to do this to integrate with an existing system. In general, I think there are valid scenarios for this problem, and it should have a workable solution.</p>
  
  <p>What's the right way to implement SendAsync in this case, so that I execute the IO bound Task asynchronously and then continue to asynchronously execute the inner handler?</p>
  
  <p>The key point is that I want to be certain that the request thread is not left blocked at any point.</p>