title: HttpWebRequest and Parallel.ForEach causes time out after spawning certain number of threads
body: <p>I have ran into a problem and I am searching for the best way to handle it. I am using HttpWebRequest in a Parallel.ForEach loop (the code is below). I have tested the program on more than two dozen machines and a number of different types of connections and it had worked flawlessly until now. </p>
  
  <p>Today, my ADSL modem died and was replaced by the ISP with a new one - now, when I run the program and as soon as the spawned threads get to 35-40, all I get is time outs; at that point, even when I try to load the websites in my browser, they time out. </p>
  
  <p>My guess is that the modem cannot handle the concurrent connections - the question is how do I prevent this from happening? Of course, I can cap the number of concurrent connections, but there should be a better way to handle this? </p>
  
  <p>Any help is greatly appreciated.</p>
  
  <pre><code>string pageContent;
  HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(webSiteUrl);
  myReq.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)";
  
  myReq.Method = "GET";
  myReq.Accept = "text/html";
  
  myReq.Timeout = webRequestTimeout; //set to generous 90 seconds
  myReq.ReadWriteTimeout = webRequestTimeout;  //set to 90 seconds
  
  
  HttpWebResponse myres = (HttpWebResponse)myReq.GetResponse();
  
  using (StreamReader sr = new StreamReader(myres.GetResponseStream(), Encoding.Default))
  {
      pageContent = sr.ReadToEnd();
  
  }
  
  myres.Close();
  </code></pre>