C# 获取c中进程的打开线程数#
我想获得由我从我的应用程序运行到我使用此代码运行的应用程序的进程打开的线程数C# 获取c中进程的打开线程数#,c#,windows,multithreading,C#,Windows,Multithreading,我想获得由我从我的应用程序运行到我使用此代码运行的应用程序的进程打开的线程数 p.StartInfo = new ProcessStartInfo(Application.StartupPath + @"\bin\childApp.exe", parametr); p.StartInfo.CreateNoWindow = true; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.UseShellExecute =
p.StartInfo = new ProcessStartInfo(Application.StartupPath + @"\bin\childApp.exe", parametr);
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
我想知道我运行这个应用程序打开了多少线程
我在这项工作中使用了这段代码,但是当我每秒都使用它时,CPU的使用量非常大
private int GetThread(string AppId)
{
try
{
string queryString = "select ThreadCount from Win32_Process WHERE ProcessId='" + AppId + "'";
SelectQuery query = new SelectQuery(queryString);
ManagementScope scope = new System.Management.ManagementScope(@"\\.\root\CIMV2");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection processes = searcher.Get();
int result = 0;
foreach (ManagementObject mo in processes)
{
result = Convert.ToInt32(mo["ThreadCount"]);
break;
}
return result;
}
catch
{
return 0;
}
}
还有其他方法吗?不要每秒钟都打电话。每15秒调用一次GetThread计数。您的CPU使用率仍然很高吗?@user1983460很高兴我能帮上忙
p.Refresh();
var threadCount = p.Threads.Count;