I also understand I can also use this programatically by creating a performance counter by using System.Diagnostics.PerformanceCounter
, and get the counter value using NextValue() method.
Process p = Process.GetProcessById(10204);
PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set - Private", p.ProcessName);
PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% User Time", p.ProcessName);
while (true)
{
Thread.Sleep(1000);
double ram = ramCounter.NextValue();
double cpu = cpuCounter.NextValue();
Console.WriteLine("RAM: " + (ram / 1024 / 1024) + "MB");
Console.WriteLine("CPU: " + (cpu) + " %");
}
I found this code online and In Here I am more insterested in Calculating Average CPU and Average RAM at the end of this test and store it in a Var to compare it against another variable. any nice ideas
thanks