ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

C#: CPU and RAM Performance Meter

CPUandRAMMeterC#fig.4In this tutorial, I will teach you how to create a CPU and RAM Performance meter in C#.NET. This method will calculate the percentage and determine the usage of the RAM and CPU of a computer.

 

Let’s begin:

Open Microsoft Visual Studio 2008, create a new Windows Form Application for C# and drag the Label, ProgressBar, PerformanceCounter and a Timer. It will look like this.

CPUandRAMMeterC#fig.1

 

After that, click the “pcCPU” PerformanceCounter and go to the properties. In properties of “pcCPU”, select “Processor” for the Category Name,“% Processor Time” for the Counter Name and “_Total” for the Instance Name.

CPUandRAMMeterC#fig.2

 

Then, click  the other PerformanceCounter named “pcRAM” and go to the properties. In the properties, select “Memory” for Category Name and “ %Commited Bytes in Use” for the Counter Name.

CPUandRAMMeterC#fig.3

 

After setting up the two performances counter, double-click a Timer to fire the “Tickevent handler. Then, setup the performance and the percentage of the CPUand RAM of the computer in the method.

private void timer1_Tick(object sender, EventArgs e)
 {
 
 //'SET THE PERFORMANCE VALUE OF THE RAM AND CPU TO THE PROGESSBAR
 progCPU.Value =(int)pcCPU.NextValue();
 progRAM.Value =(int)pcRAM.NextValue();
 
 //'SET THE PROGRESS BAR VALUE TO THE LABEL TO KNOW WHAT IS THE PERCENTAGE OF THE PROCESS.
 lblCPU.Text = progCPU.Value.ToString() + "%"; 
 lblRAM.Text = progRAM.Value.ToString() + "%";
 }

 

Go back to the Design Views, and double-click the Form and do the following code to setup interval and start the timer in the first load of the Form.

 private void Form1_Load(object sender, EventArgs e)
 {
 //'INITIALIZE THE INTERVAL OF THE TIMER TO 500.
 timer1.Interval = 500;
 //'START THE TIMER
 timer1.Start();
 }

Output:

CPUandRAMMeterC#fig.4

For all students who need programmer for your thesis system or anyone who needs a source code in any programming languages. You can contact me @ :

 
Email – jannopalacios@gmail.com
Mobile No. – 09305235027 – tnt

 

Download Sourcecode

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!