G
Guest
I have a problem with the threadpool I can't seem to figure out.
If I use ThreadPool.QueueUserWorkItem to queue say 25 work items,
I would expect the Threadpool to give me the 25 free threads of the thread
pool i.e. execute my WaitCallback method 25 times instantly. However, there
seems to be about 0.5 sec. delay in pulling each thread of the queue.
Running the test code
public void WaitCallback( object state )
{
System.Diagnostics.Debug.WriteLine("Thread "+((int)state).ToString()+"
started");
Thread.Sleep(10000);
}
for( int i =0; i<50; i++)
ThreadPool.QueueUserWorkItem(new WaitCallback(WaitCallback),i);
I would expect the threadpool to instantly give me all available threads
thus executing the WaitCallback method 25 times. However, it takes at least
25 seconds for the pool to kick off 25 threads.
If you do not get the threads immediately, this in my book would make the
Threadpool completely useless for server purposes and any other for that
matter.
Is this as designed or am I doing something wrong ?
Regards
Per Millard
Systems Architect
Copenhagen
Denmark
If I use ThreadPool.QueueUserWorkItem to queue say 25 work items,
I would expect the Threadpool to give me the 25 free threads of the thread
pool i.e. execute my WaitCallback method 25 times instantly. However, there
seems to be about 0.5 sec. delay in pulling each thread of the queue.
Running the test code
public void WaitCallback( object state )
{
System.Diagnostics.Debug.WriteLine("Thread "+((int)state).ToString()+"
started");
Thread.Sleep(10000);
}
for( int i =0; i<50; i++)
ThreadPool.QueueUserWorkItem(new WaitCallback(WaitCallback),i);
I would expect the threadpool to instantly give me all available threads
thus executing the WaitCallback method 25 times. However, it takes at least
25 seconds for the pool to kick off 25 threads.
If you do not get the threads immediately, this in my book would make the
Threadpool completely useless for server purposes and any other for that
matter.
Is this as designed or am I doing something wrong ?
Regards
Per Millard
Systems Architect
Copenhagen
Denmark