running out of threads in the ThreadPool

T

Tony Johansson

Hi!

I have check that the default available threads in the ThreadPool is 250 so
I made this small check just to see what happen what I run out of threads.

I noticed that I didn't get any kind of error such as execption or things
like that.
The only thing that happen is that no more threads is being used because
there is no one left.

This seems like a strange situation that I don't get an exeption ?
Give me a comment about this.

static void Main(string[] args)
{
for (int i = 0; i < 260; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), i);
}
}

private static void DoWork(object o)
{
Console.WriteLine("Number = {0}",(int)o);
Thread.Sleep(9999999);
}

//Tony
 
A

Alberto Poblacion

Tony Johansson said:
I have check that the default available threads in the ThreadPool is 250
so
I made this small check just to see what happen what I run out of threads.

I noticed that I didn't get any kind of error such as execption or things
like that.
The only thing that happen is that no more threads is being used because
there is no one left.

This seems like a strange situation that I don't get an exeption ?
[...]
ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), i);

Look carefully at the name of the method you are calling:
QUEUEuserworkitem. Doesn't it suggest something? It is queuing the request
so that it will be allocated a thread when one becomes available in the
ThreadPool.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top