Hi,
I'm a little confused about one aspect of the .NET ThreadPool: namely, how you can tell how many of its 'Available' threads are idle ones waiting to be reused, and how many haven't yet been created.
The summary for the GetAvailableThreads()
method states that it:
Retrieves the difference between the maximum number of thread pool threads returned by the GetMaxThreads method, and the number currently active.
Any thread that is 'active' is busy working and therefore not available for reuse, but how many are 'available' for reuse versus 'available' because they haven't been created?
I know that the GetMinThreads()
method returns the absolute minimum number of threads the framework will maintain in the pool for reuse, but that doesn't necessarily equate to the current number of idle threads - does it? I'm under the impression that idle threads will hang around in the ThreadPool and only be pruned back to the minimum if they go unused for some time.
This is important because, according to the docs:
When all thread pool threads have been assigned to tasks, the thread pool does not immediately begin creating new idle threads. To avoid unnecessarily allocating stack space for threads, it creates new idle threads at intervals. The interval is currently half a second, although it could change in future versions of the .NET Framework.
I want to check if my application is having to create an excessive number of 'new' threads in the pool - slowing it down - but I'm not sure how to do that without being able to figure out how many idle, ready-to-reuse threads I have hanging around.
Any ideas welcome. Thanks!