I'm trying to get cpu load for a background process; Background process
Using Performance Counter
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) + " %");
}
It does pretty well on (Apps), but fails on Backgorund returning 0 every time; I'm confused; What's the correct way of retrieving cpu load for thees sort of process?