Created
August 27, 2012 19:50
-
-
Save nicosantangelo/3491728 to your computer and use it in GitHub Desktop.
Get performance usage for c#
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
using System.Diagnostics; | |
public static class PerformanceManager | |
{ | |
static PerformanceCounter cpuCounter; | |
static PerformanceCounter ramCounter; | |
static PerformanceManager() | |
{ | |
cpuCounter = new PerformanceCounter(); | |
cpuCounter.CategoryName = "Processor"; | |
cpuCounter.CounterName = "% Processor Time"; | |
cpuCounter.InstanceName = "_Total"; | |
ramCounter = new PerformanceCounter("Memory", "Available MBytes"); | |
} | |
public static string getCurrentCpuUsage() | |
{ | |
return cpuCounter.NextValue() + "%"; | |
} | |
public static string getAvailableRAM() | |
{ | |
return ramCounter.NextValue() + "MB"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment