Skip to content

Instantly share code, notes, and snippets.

@nicosantangelo
Created August 27, 2012 19:50
Show Gist options
  • Save nicosantangelo/3491728 to your computer and use it in GitHub Desktop.
Save nicosantangelo/3491728 to your computer and use it in GitHub Desktop.
Get performance usage for c#
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