开发者

How to get the active thread count?

I have a program which calls a C++ library. The program proce开发者_如何学Gosses has a large number of threads (50 - 60). Most of them seem to be created in C++ and I suspect most are suspended/waiting.

How do I find how many of these threads are active at a given point in time?


To actually determine the count of active threads, it's necessary to check the ThreadState property of each thread.

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


You could use Process Explorer to inspect threads. It will tell you in realtime how much CPU each is consuming, and can give you individual stack traces, which will indicate what they are blocked on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜