如何使用 System.Diagnostics.PerformanceCounter跟踪进程的内存和 CPU 使用情况?
最佳答案
对于每个进程数据:
Process p = /*get the desired process here*/;
PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set", p.ProcessName);
PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", p.ProcessName);
while (true)
{
Thread.Sleep(500);
double ram = ramCounter.NextValue();
double cpu = cpuCounter.NextValue();
Console.WriteLine("RAM: "+(ram/1024/1024)+" MB; CPU: "+(cpu)+" %");
}
性能计数器除了工作集和处理器时间还有其他计数器。
关于c# - 使用 PerformanceCounter 跟踪每个进程的内存和 CPU 使用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3411805/