Created
December 30, 2017 17:17
-
-
Save mjs3339/78c5d038ed70882f9fe48594df4bfe9b to your computer and use it in GitHub Desktop.
C# Get Processor Time using PerformanceCounter
This file contains 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
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