I need to get CPU usage of a process that is a variable.
Ex:
var process = wait.exe
And check the wait.exe, if it has reached 100 CPU usage.
How can I do this?
I need to get CPU usage of a process that is a variable.
Ex:
var process = wait.exe
And check the wait.exe, if it has reached 100 CPU usage.
How can I do this?
You can use the class PerformanceCounter
that is in the namespace System.Diagnostics
public int GetCpuUsage()
{
System.Diagnostics.PerformanceCounter cpuCounter;
cpuCounter = new System.Diagnostics.PerformanceCounter("Process", "% Processor Time", System.Diagnostics.Process.GetProcessesByName("wait").First().ProcessName);
return (int)cpuCounter.NextValue();
}