Windows Forms: Create CPU & RAM Monitor with Real time Charts in C#

This tutorial show you how to Create CPU & RAM monitor with real time charts using Metro Framework, Performance Counter and Chart control in C#

As you know, Ram & CPU Meter is a small application which resides on your desktop and provides useful information about your computer's processor and memory usage.

The PerformanceCounter component provides information as to how well the operating system or an application, service or driver is performing. You should use the Performance Counters API when you want to provide or consume counter data.

Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "CPURAM" and then click OK

cpu and ram monitor with real time chart

Step 2: Right click on your project select Manage NuGet Packages -> Search metro framework -> Install

install metro framework

If you don't see the metro framework in your toolbox, you can view How to download and install metro framework

Step 3: From your visual studio toolbox drag the metro progress bar, metro label and chart control to your form, then design ram & cpu meter form as shown below.

cpu and ram monitor with real time chart

Step 4: Add a Timer and PerformanceCounter to your metro form, then add a tick event handler to timer control

private void timer_Tick(object sender, EventArgs e)
{
    float fcpu = pCPU.NextValue();
    float fram = pRAM.NextValue();
    //Set value to cpu and ram
    metroProgressBarCPU.Value = (int)fcpu;
    metroProgressBarRAM.Value = (int)fram;
    //Update value to cpu and ram label
    lblCPU.Text = string.Format("{0:0.00}%", fcpu);
    lblRAM.Text = string.Format("{0:0.00}%", fram);
    //Draw cpu and ram chart
    chart1.Series["CPU"].Points.AddY(fcpu);
    chart1.Series["RAM"].Points.AddY(fram);
}

You should set start the timer in your Form_Load event

private void Form1_Load(object sender, EventArgs e)
{
    timer.Start();
}

VIDEO TUTORIALS