Skip to content

Instantly share code, notes, and snippets.

@mjs3339
Created December 30, 2017 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjs3339/78c5d038ed70882f9fe48594df4bfe9b to your computer and use it in GitHub Desktop.
Save mjs3339/78c5d038ed70882f9fe48594df4bfe9b to your computer and use it in GitHub Desktop.
C# Get Processor Time using PerformanceCounter
public static class CPUTotalPC
{
private static PerformanceCounter _CPUsage;
public static double CPULoad
{
get
{
if (_CPUsage == null)
{
try
{
_CPUsage = new PerformanceCounter("Processor", "% Processor Time", "_Total");
}
catch
{
return 0;
}
}
return _CPUsage.NextValue();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment