Get CPU usage of a process in int C#

Asked

Viewed 546 times

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?

1 answer

1


You can use the class PerformanceCounter that is in 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();

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.