title: HttpClient - task was cancelled - How to get the exact error message?
body: <p>I have the following test code. I always get the "Task was cancelled" error after looping 316934 or 361992 times.</p>
  
  <p>If I am not wrong, there are two possible reasons why the task was cancelled a) HttpClient got timeout or b) too many tasks in queue and some tasks got time-out. </p>
  
  <p>I couldn't find the documentation about the limitation in queueing the tasks. And I tried creating more than 500K tasks and no time-out. I guess the reason "b" might not be right. </p>
  
  <p>Q1. Is there any other reason that I missed out? </p>
  
  <p>Q2. If it's because HttpClient timeout, how can I get the exact exception message instead of "TaskCancellation" exception. </p>
  
  <p>Q3. What would be the best way to fix it? Should I introduce the throttler? </p>
  
  <p>Thanks!</p>
  
  <pre><code>var _httpClient = new HttpClient();
  _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml");
  _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
  _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
  _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
  
  int[] intArray = Enumerable.Range(0, 600000).ToArray();
  
  var results = intArray                
      .Select(async t =&gt; {
  
          using (HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://www.google.com")) {
              log.Info(t);
  
              try {
  
                  var response = await _httpClient.SendAsync(requestMessage);
                  var responseContent = await response.Content.ReadAsStringAsync();
  
                  return responseContent;
              }
              catch (Exception ex) {
                  log.ErrorException(string.Format("SoeHtike {0}", Task.CurrentId), ex);
              }
              return null;
          }
      });
  
  Task.WaitAll(results.ToArray());
  
  Console.ReadLine();
  </code></pre>
  
  <p>Here is the step to replicate the issue. </p>
  
  <ol>
  <li><p>Create a Console Project in VS 2012. </p></li>
  <li><p>Please copy and paste my code in Main. </p></li>
  <li><p>Put the breakpoint at this line " log.ErrorException(string.Format("SoeHtike
  {0}",
  Task.CurrentId),
  ex);"</p></li>
  </ol>
  
  <p>Run the program in debug mode. Wait for a few minutes. (maybe 5 minutes? )  I just tested my code and I got the exception after 3 mins. If you have fiddler, you can monitor the requests so that you know the program is still running or not. </p>
  
  <p>Feel free to let me know if you can't replicate the issue. </p>