How to get the counter of active threads?

I have a program that calls a C ++ library. Program processes have a large number of threads (50-60). Most of them seem to be built in C ++, and I suspect most of them are paused / waiting.

How to find out how many of these threads are currently active?

+6
multithreading c #
source share
2 answers

To really determine the number of active threads, you need to check the ThreadState property for each thread.

 ((IEnumerable)System.Diagnostics.Process.GetCurrentProcess().Threads) .OfType<System.Diagnostics.ProcessThread>() .Where(t => t.ThreadState == System.Diagnostics.ThreadState.Running) .Count(); 
+12
source share

You can use Process Explorer to check threads. It will tell you in real time how much CPU it consumes, and can give you separate stack traces that indicate what they are locked on.

+4
source share

All Articles