title: HttpClient in using statement causes Task cancelled
body: <p>I created a <code>FileResult : IHttpActionResult</code> webapi return type for my api calls. The FileResult downloads a file from another url and then returns the stream to the client. </p>
  
  <p>Initially my code had a <code>using</code> statement like below:</p>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; ExecuteAsync(CancellationToken cancellationToken)
  {
      try
      {
          HttpResponseMessage response;
          using (var httpClient = new HttpClient())
          {
  
              response = new HttpResponseMessage(HttpStatusCode.OK)
              {
                  Content = new System.Net.Http.StreamContent(
                                      await httpClient.GetStreamAsync(this.filePath))
              };
          }
          return response;
      }
      catch (WebException exception)
      {...}
  }
  </code></pre>
  
  <p>However this would intermittently cause a <code>TaskCanceledException</code>. I know that if the HttpClient is disposed before the asychronous call is finished the Task's state will change to canceled. However since I use an <strong>await</strong> in: <code>Content = new System.Net.Http.StreamContent(await httpClient.GetStreamAsync(this.filePath))</code> that should prevent the HttpClient from being disposed off in the middle of the task completion. </p>
  
  <p><strong>Why does that task get canceled?</strong> It is not because of a timeout since this has happened on the smallest requests and doesn't always occur on large requests.</p>
  
  <p>When I removed the <code>using</code> statement the code worked properly:</p>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; ExecuteAsync(CancellationToken cancellationToken)
  {
      try
      {
          HttpResponseMessage response;
          var httpClient = new HttpClient();
  
          response = new HttpResponseMessage(HttpStatusCode.OK)
          {
              Content = new System.Net.Http.StreamContent(
                                  await httpClient.GetStreamAsync(this.filePath))
          };
          return response;
      }
      catch (WebException exception)
      {...}
  }
  </code></pre>
  
  <p>Any idea why the using caused the issue?</p>