How to monitor the state of the .Net Thread Pool?

3k Views Asked by At

Is it possible to find out the state of threads in the threadpool? Our application is sometimes using a lot of threads and these are mostly down to calls to ThreadPool.QueueUserWorkItem. However when the application isn't really doing much the thread count never decreases. I would have thought eventually these threads would be stopped.

Reading around I believe they should enter a suspended state when they have completed all tasks then if not reused eventually wake up and be terminated.

The application is using the .Net Compact Framework v2. It could be the threads are getting stuck, however when I pause the application in visual studio the threads window only displays around 7-8 threads. The remote process viewer bundled with v2005 states the process is using in excess of 40 threads. I can only assume it is just thread pool threads sat waiting to be used.

What approach can be used to test that the work in the ThreadPool is being completed and threads are being released back into the pool?

EDIT 1

Thread Pool

This is taken from the .NET Compact Framework Remote Performance Monitor and the thread pool thread count is at 25. However like i said in visual studio itself there certainly isn't 25 threads, only about 7 or 8.

0

There are 0 best solutions below