title: How to retry a webclient request that gets timeout exception
body: <p>Im making a custom <code>WebClient</code> class with some functionalities that is not available in the <code>WebClient</code> framework class. I actually using this class like this:</p>
  
  <pre><code>using (var client = new CustomWebClient(10000))
  {
       client.Tries = 5; //Number of tries that i want to get some page
       GetPage(client);
  }
  </code></pre>
  
  <p>The CustomWebClient class:</p>
  
  <pre><code> public class CustomWebClient : WebClient
   {
      public CookieContainer Cookies { get; }
      public int Timeout { get; set; }
      public int Tries { get; set; }
  
      public CustomWebClient () : this(60000)
      {
      }
  
      public CustomWebClient (int timeOut)
      {
          Timeout = timeOut;
          Cookies = new CookieContainer();
          Encoding = Encoding.UTF8;
      }
  
      protected override WebRequest GetWebRequest(Uri address)
      {
         // some code here, but calling the base method
      }
  
      //this method actually is important to make the Tries logic.
      protected override WebResponse GetWebResponse(WebRequest request)
      {
          try
          {
              return base.GetWebResponse(request);
          }
          catch (WebException ex)
          {
              if(ex.Status == WebExceptionStatus.Timeout || ex.Status == WebExceptionStatus.ConnectFailure)
              if (--Tries == 0)
                  throw;
  
              GetWebResponse(request);
          }
      }
  
     }
  </code></pre>
  
  <p>When the 10000 miliseconds ends, i the  <code>base.GetWebResponse(request);</code> throws an <code>WebException</code> with <code>WebExceptionStatus.Timeout</code> status. And the Tries is subtracted. But when i execute the <code>GetWebResponse(request);</code> to retry obtain the response, it dont waits 10000 miliseconds and throws the exception again and it goes on until the 5 tries. How to obtain the response again, making another request?</p>
  
  <p>Thanks.</p>