如何获得活动线程数? [英] How to get the active thread count?

查看:92
本文介绍了如何获得活动线程数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用C ++库的程序.程序进程具有大量线程(50-60).它们中的大多数似乎是用C ++创建的,我怀疑大多数已暂停/正在等待.

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 suspended/waiting.

在给定的时间点,我如何找到这些线程中有多少处于活动状态?

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

推荐答案

要真正确定活动线程的数量,必须检查每个线程的ThreadState属性.

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();

这篇关于如何获得活动线程数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆