Get CPU usage of a process in int C #

5

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?

    
asked by anonymous 12.04.2017 / 15:50

1 answer

1

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();

}
    
12.04.2017 / 18:11