How to Display Processor Usage of Dual Core Processors

No.of Views1584
Bookmarked0 times
Downloads 
Votes0
By  kirtan007   On  16 Feb 2010 00:02:48
Tag : CSharp , Windows Forms
How to Display Processor Usage of Dual Core Processors
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Ever Wondared how Task manager Displays Information about Current Processor Usage and its Cores
Here is What we gonna do it .


Technologies:

.net 2.0/3.5

Language:

C#

Prerequisite

1. .NET Framework 3.5/2.0

2. Visual Studio 2008/2005

Implementation

First of All Setup the GUI like Below Take 3 Progressbar , 6 lables to display Information

ok Now its all About retriving Processor Info so

Import Name space

{codecitation class="brush: csharp; gutter: true;" width="650px"}


using System.Diagnostics;

{/codecitation}

On Form Load We are Creating One Timer Instance then Initialize 3 performance Counter Objects

and Now in Times tick Event We Assigning thos Values to Progressbar Values .

and Display Their Usage Percentage in labels too ..


Here is Full Code How you Gonna Perform that

{codecitation class="brush: csharp; gutter: true;" width="650px"}


public partial class Form1 : Form
{

// Delare Global Performance Counters
PerformanceCounter p1, p2, p3;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

// Initialize Timer
Timer t1 = new Timer();

t1.Tick += new EventHandler(t1_Tick);
t1.Enabled = true;

p1 = new PerformanceCounter("Processor", "% Processor Time", "_Total", true);
p2 = new PerformanceCounter("Processor", "% Processor Time", "0", true);
p3 = new PerformanceCounter("Processor", "% Processor Time", "1", true);

}

public void t1_Tick(Object Sender, EventArgs e)
{

// Set Progressbar value and Its Corresponding Label Value

progressBar1.Value = Convert.ToInt32(p1.NextValue());
lblTotalPercentage.Text = progressBar1.Value + "%";

progressBar2.Value = Convert.ToInt32(p2.NextValue());
lblCore1Percentage.Text = progressBar2.Value + "%";

progressBar3.Value = Convert.ToInt32(p3.NextValue());
lblCore2Percentage.Text = progressBar3.Value + "%";
}
}
}

{/codecitation}


Thats it You are Done !!

Conclusion

Article Explaines how to retrive inforamtion about processor usage in DualCore as well as Single Core Processors .

Thank you

About the Author


Kirtan Patel
- Bachelor of Computer Application .
- File Handling with C#
- Registry Programming With C#.
- Knowledge of Virus Programming .
- Working With third party controls like Telerik and Component Factory .
- P/invoke Win32 API.
- SQL Server Database Applications
- Client/Server Database Programming
Expertise in : C# , Asp.net ,Vb.net , SQL Server , Designing Elegant look Web interface
Familiar With : C/C++ , Core Java , Java Script , Dream weaver templates , fire Works ,PHP ,Photo shop
and Graphics
Databases: Microsoft SQL Server 2005 , Microsoft Access and Some MySQL
Occupation: Student
 
Sign Up to vote for this article
 
About Author
 
kirtan007
Occupation-
Company-
Member Type-Senior
Location-Not Provided
Joined date-02 Jul 2009
Home Page-http://kirtan.uni.cc
Blog Page-
He completed his Bachelor of Computer Application from Gujarat University 2009 .He is doing Master of Computer Application from Gujarat Technological University right now .. His area of Interests are Web Hacking , C# .net Windows form ,asp.net , WPF ,Silverlight ,SQL Server and Some PHP.
 
 
Other popularSectionarticles
Comments
By:term papersDate Of Posted:7/1/2010 2:29:10 PM
term papers
I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information… Regards
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top