0
我想獲得CPU負載的後臺進程; Background processC#後臺進程CPU負載使用PerformanceCounter
使用性能計數器
PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set", process.ProcessName);
PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", process.ProcessName);
ramCounter.NextValue();
cpuCounter.NextValue();
while (true)
{
Thread.Sleep(500);
double ram = ramCounter.NextValue();
double cpu = cpuCounter.NextValue();
Console.WriteLine("RAM: " + (ram/1024/1024) + " MB; CPU: " + (cpu) + " %");
}
它確實相當不錯的軟件(Apps),但卻未能在Backgorund返回每次0; 我很困惑; 什麼是正確的方式來檢索CPU類型的過程?
檢查這個例子
而且GetProcessInstanceName。 http://www.codeproject.com/Articles/10258/How-to-get-CPU-usage-of-processes-and-threads – active92
該進程有幾個活動實例,都具有相同的名稱。那麼你究竟在監視哪一個? http://stackoverflow.com/a/9115662/17034 –
我正在運行拋出所有這些,結果是相同的0 cpu負載; 'List prc = runningNow.Where(x => x.ProcessName == txtApp.Text).ToList(); foreach(處理過程在prc中) {..' –
MultyPulty