title: HttpClient - how to figure out if server is down faster?
body: <p>I'm using .NET <code>HttpClient</code> to send requests to my server. I have set <code>HttpClient.Timeout</code> property to 10 seconds so i'm getting a <code>A task was cancelled</code> exception whenever the server fails to process my request in less than 10 seconds. Good until here. </p>
  
  <p>However, if the server is shut down it takes for the <code>HttpClient</code> around ~20 seconds to return a proper exception such as the one in the picture. <img src="https://i.stack.imgur.com/uhzsS.png" alt="enter image description here"></p>
  
  <p>I would like to see this exception faster than 10 seconds to be able to distinguish between Server Down and Operation took too long scenarios. I can't find anything about this in msdn documentation. Is there any timeout that can be set on the <code>HttpClient</code>? </p>
  
  <p>Here's how i'm constructing the <code>HttpClient</code> </p>
  
  <pre><code> var webRequestHandler = new WebRequestHandler
          {
              UseProxy = false,
              Proxy = null,
              AllowPipelining = false,
              ContinueTimeout = TimeSpan.Zero,
              UseCookies = false,
              AllowAutoRedirect = false,
          };
   var httpClient = new HttpClient(webRequestHandler);
   httpClient.Timeout = timeout;
  
    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json");
    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", userAgent);
    httpClient.DefaultRequestHeaders.ExpectContinue = false;
  </code></pre>