title: HttpWebRequest.BeginGetResponse blocks 30-60 seconds
body: <p>currently in one of our apps I see big lags when executing the first HTTP Webrequest. According to our logs there is a lag of 30 - 60 seconds. It blocks at HttpWebRequest.BeginGetResponse </p>
  
  <p>Here is a quote from the MSDN:</p>
  
  <blockquote>
    <p>The BeginGetRequestStream method requires some synchronous setup tasks
    to complete (DNS resolution, proxy detection, and TCP socket
    connection, for example) before this method becomes asynchronous. As a
    result, this method should never be called on a user interface (UI)
    thread because it might take some time, typically several seconds. In
    some environments where the webproxy scripts are not configured
    properly, this can take 60 seconds or more. The default value for the
    downloadTime attribute on the  config file element is
    one minute which accounts for most of the potential time delay.</p>
  </blockquote>
  
  <p>I understand that there is DNS resolution, proxy detection and other stuff required. But 30-60 seconds is way too long. When I enter the same URL in any browser I get the page immediately. When I resolve DNS manual there is also no delay.
  All concurrent requests to the same URI don't block. When I restart the application the first request blocks again for min. 30 seconds.</p>
  
  <p>Is this a known problem? Is there a bug? We see this on different machines, So I don't think my developer machine is the problem.</p>
  
  <p>Here is some example code:</p>
  
  <pre><code>private void TestWebRequest()
  {
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://matrix.ag-software.de/http-bind");
     request.ContentType = "text/xml; charset=utf-8";
     request.Method = "POST";   
     request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);            
  }
  
  private void GetRequestStreamCallback(IAsyncResult result)
  {
     //
  }
  </code></pre>
  
  <p><strong>update:</strong> This must be a problem with my Windows 7 Installation. I have tested 2 other machines and can't cause the same problem there. I have seen logfiles from customers with exactly the same problems. This seems to happen under some conditions on some machines.</p>