views:

190

answers:

1

Let's say I have the following code :

ThreadPool.SetMinThreads(100, 100); 
for (int i = 0; i < 100; i++)
{
  var request = WebRequest.Create(url);
  request.BeginGetResponse(ar =>
 {
  //inside AsynchCallBack method for request.BeginGetResponse()
  var response = (HttpWebResponse)request.EndGetResponse(ar);

  string html;
  using (var receiveStream = response.GetResponseStream())
  using (var readStream = new StreamReader(receiveStream
                       , Encoding.UTF8))
  {
   html = readStream.ReadToEnd();
  }

            Console.WriteLine(Thread.CurrentThread.ManagedThreadId);

 }, null
 );
}

I'm expecting to see quite a lot of threads when writing to the console the ManagedThreadId - of course I am wrong :) . I generally see only 2 different thread Ids and once in a while 3 thread Ids.

Why this behavior ? What am I missing?

+2  A: 

I think you are hitting the connection limit.

jsight
Wow - that was fast :) . Thank you very much.
sirrocco