Skip to content

Instantly share code, notes, and snippets.

@mjs3339
Created March 24, 2020 09:22
Show Gist options
  • Save mjs3339/eb70368d6c6cd509260b8eef51331e38 to your computer and use it in GitHub Desktop.
Save mjs3339/eb70368d6c6cd509260b8eef51331e38 to your computer and use it in GitHub Desktop.
Uses the PerformanceCounter to get the Cpu Usage
using System.Diagnostics;
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