How to get the active thread count?

后端 未结 2 1881
孤城傲影
孤城傲影 2021-01-18 04:20

I have a program which calls a C++ library. The program processes has a large number of threads (50 - 60). Most of them seem to be created in C++ and I suspect most are susp

2条回答
  •  甜味超标
    2021-01-18 05:00

    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()
        .Where(t => t.ThreadState == System.Diagnostics.ThreadState.Running)
        .Count();
    

提交回复
热议问题