ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

How to Create CPU and RAM Meter in VB.NET

In this tutorial, I will teach you how to create a CPU and RAM meter in VB.NET. With this, you will be able to determine the usage and it calculates the percentage of the RAM and CPU in your computer.

 

Let’s begin:

 
Open Visual Basic, create a new Windows Form Application and drag the Label, ProgressBar, PerformanceCounter and a Timer. Name the two PerformanceCounters, “pc_CPU” and the other one is “pc_RAM”. Name the two Labels into “lbl_CPU” and “lbl_RAM”. Then, name the two ProgressBars into “pb_CPU”and “pb_RAM”.
ramcpumeterform1
After setting up the Form, click the “pc_CPU” PerformanceCounter and go to the properties. In properties of “pc_CPU”, select “Processor” for the Category Name,“% Processor Time” for the Counter Name and “_Total” for the Instance Name.
ramcpumeterform2

 

After setting up the properties of the “pc_CPU”, click the other PerformanceCounter named “pc_RAM” and go to the properties. In the properties, select “Memory” for Category Name and “ % Commited Bytes in Use” for the Counter Name.
ramcpumeterform3

Now, double click a Timer to fire the “Tick” event handler. In the “Tick” event handler, you have to setup the performance and the percentage of the CPU and RAM of the computer.

  1. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  2. 'SET THE PERFORMANCE VALUE OF THE RAM AND CPU TO THE PROGESSBAR
  3. pb_CPU.Value = pc_CPU.NextValue
  4. pb_RAM.Value = pc_RAM.NextValue
  5. 'SET THE PROGRESS BAR VALUE TO THE LABEL TO KNOW WHAT IS THE PERCENTAGE OF THE PROCESS.
  6. lbl_cpu.Text = pb_CPU.Value & "%"
  7. lbl_ram.Text = pb_RAM.Value & "%"
  8. End Sub

Go back to the Design Views and double click the Form. In the Form1_Load, you have to start the timer and setup the interval of it.

  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. 'INITIALIZE THE INTERVAL OF THE TIMER TO 500.
  3. Timer1.Interval = 500
  4. 'START THE TIMER
  5. Timer1.Start()
  6. End Sub

You can download the Complete Source Code.

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!