Get CPU and Memory usage of system in C#

PerformanceCounter cpuCounter=new PerformanceCounter("Processor", "% Processor Time", "_Total");
PerformanceCounter ramCounter= new PerformanceCounter("Memory", "Available MBytes");

// The method nextValue() always returns a 0 value on the first call. So you have to call this method a second time
var cpuUsage = cpuCounter.NextValue();
string cpuUsageStr = string.Format("{0:f2} %",cpuUsage);

var ramAvailable = ramCounter.NextValue();
string ramAvaiableStr = string.Format("{0} MB", ramAvailable);

References :