KaustubhK
KaustubhK

Reputation: 775

Number of available threads in threadpool

In a Threadpool, I have set maximum number of threads.I want number of worker threads are available. i tried.

     ThreadPool.GetAvailableThreads(out x, out y);

Using this, I got number of available threads (x) which was only decreasing.There was no increase in a number of available threads (x) even after their task was done. How to get actual number of available threads in thread pool.

Upvotes: 2

Views: 1379

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273244

The GetAvailableThreads() method does not tell you how many threads there are, it returns how many extra threads still can be created.

From MSDN:

When GetAvailableThreads returns, the variable specified by workerThreads contains the number of additional worker threads that can be started,

And concerning

here was no increase in a number of available threads (x) even after their task was done.

How long did you wait? The pool will only slowly destroy idle threads.

Upvotes: 3

Related Questions