views:

105

answers:

1

I want to observe the Threadpool when debugging Visual C# without changing the code (the program is already running) can I add code to the monitoring? Perhaps that I ask for the Threadpool.AvailableThreads method when debugging. I am developing in Visual Studio 2008.

EDIT: I just figured out that within my threads (i.e. in the method I put in the thread pool) there are mysql queries executed and they occupy the thread pool.

+1  A: 

It is unclear to me what exactly you want to monitor. In VS the threads window will show you all the threads and by switching between threads you can monitor their respective call stacks. If you want additional detail, you may want to look into WinDbg which will let you inspect additional detail (albeit not as easily as VS).

EDIT: Answer to question in comment. This is a simplification, but generally the thread pool manages a number of threads that are used to run different tasks such as QueueUserWorkItem. There is nothing special about the threads in the thread pool save the fact that they are managed by the thread pool. The benefit of this is that threads can be reused. Creating new threads is an expensive operation, so by reusing the threads the cost is amortized.

You main thread is not handled by the thread pool and neither are any other threads you create using the Thread class.

Brian Rasmussen
perhaps using the window for direct debugging? What I want to know is, what threads exactly the threadpool manages? All threads of the program or just the threads that I started by QueueUserWorkItem?
Xelluloid