Created
March 24, 2020 09:22
-
-
Save mjs3339/eb70368d6c6cd509260b8eef51331e38 to your computer and use it in GitHub Desktop.
Uses the PerformanceCounter to get the Cpu Usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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