473,434 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

How to fetch CPU Usage from DOT Net

Hi All,

Is there any way to get the exact CPU Usage which is shown in Task Manager.
Any code snippet or ideas will be appreciated.

Thanx in advance,

Vijay
Jul 21 '05 #1
5 23938
Hi Vijay,

You need to use one of the Performance Counters:

Imports System.Diagnostics

Dim oPerf1 As New PerformanceCounter

oPerf1.CategoryName = "Processor"
oPerf1.CounterName = "% Processor Time"
oPerf1.InstanceName = "0"

Dim I As Integer
For I = 0 To 100
SomeListBox.Items.Add (oPerf1.NextValue)
Threading.Thread.Sleep (20)
Next

Regards,
Fergus

ps. You posted to a lot of groups there. I'm not sure how relevant this
question is to ADO and ASP.??
Jul 21 '05 #2
You can use the System.Diagnostics.PerformanceCounter class. The
PerformanceCounter component can be used for both reading existing
predefined or custom counters and writing performance data to custom
counters.
This sould get you started:

Dim myCounter As System.Diagnostics.PerformanceCounter = New
System.Diagnostics.PerformanceCounter()

myCounter.CategoryName = "Processor"
myCounter.CounterName = "% Processor Time"
myCounter.InstanceName = "_Total"
MessageBox.Show(myCounter.NextValue().ToString()) 'cpu usage

Cheers,
- Gary -
"Vijay Ram" <v_***@yahoo.com> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
Hi All,

Is there any way to get the exact CPU Usage which is shown in Task Manager. Any code snippet or ideas will be appreciated.

Thanx in advance,

Vijay

Jul 21 '05 #3
Hello,

"Vijay Ram" <v_***@yahoo.com> schrieb:
Is there any way to get the exact CPU Usage which is shown
in Task Manager. Any code snippet or ideas will be appreciated.


http://www.google.de/groups?selm=3d0....microsoft.com

Please do not include ngs in your x-post which are not related to the
topic of the question.

--
Herfried K. Wagner
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Jul 21 '05 #4
microsoft.public.dotnet.framework.adonet
microsoft.public.dotnet.framework.aspnet
microsoft.public.dotnet.framework.wmi
microsoft.public.dotnet.general
microsoft.public.dotnet.languages.vb

Actually, this is a fairly responsible group of groups for a novice dotnet'r
to query (with the exception of the adonet...). And you got a 'general'
answer. Using the Web Matrix supplied Matrix ClassBrowser (free Web Matrix
download from Microsoft!) it took more time for the ClassBrowser to load
than to find the answer to this question.

However, a "way to get the exact CPU Usage" is excluded by the Heisenberg
uncertainty principle (http://www.aip.org/history/heisenberg/p01.htm)! Do
not despair... what you can get is:

AverageBase
AverageCount64
AverageTimer32
CounterDelta32
CounterDelta64
CounterMultiBase
CounterMultiTimer
CounterMultiTimer100Ns
CounterMultiTimer100NsInverse
CounterMultiTimerInverse
CounterTimer
CounterTimerInverse
CountPerTimeInterval32
CountPerTimeInterval64
ElapsedTime
NumberOfItems32
NumberOfItems64
NumberOfItemsHEX32
NumberOfItemsHEX64
RateOfCountsPerSecond32
RateOfCountsPerSecond64
RawBase
RawFraction
SampleBase
SampleCounter
SampleFraction
Timer100Ns
Timer100NsInverse

It's all explained at
http://msdn.microsoft.com/library/de...ClassTopic.asp

"Vijay Ram" <v_***@yahoo.com> wrote in message
news:e$**************@TK2MSFTNGP09.phx.gbl...
Hi All,

Is there any way to get the exact CPU Usage which is shown in Task Manager. Any code snippet or ideas will be appreciated.

Thanx in advance,

Vijay

Jul 21 '05 #5
Hi Per,

|| However, a "way to get the exact CPU Usage" is excluded
|| by the Heisenberg uncertainty principle

Lol.
If ever there's a way round that there'll always be the Windows OS
uncertainty principle.

|| AverageBase
|| AverageCount64
||
|| Timer100Ns
|| Timer100NsInverse

These are all PerformanceCounter data types.

If you have Server Explorer in your VS, you can get a list of the actual
counters by opening this window, and expanding the nodes for Servers and your
machine.

There is also a Management Console application, Perfmon.exe, with which
you can examine the available counters.

Regards,
Fergus
Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lem | last post by:
When I use ora_xxx functions to connect to oracle 7 and fetch data from it, the English character is pretty good,but the Chinese character all turn to be '?'. what about this problem ? Is there...
3
by: Stijn Goris | last post by:
hi all, Is it possible to fetch a column from a queryresult? kind regards Stijn
2
by: Rod | last post by:
Hi, I would like to know if there is a similar function with OCI8 (oracle) to this one: mysql_data_seek ? I would like to do twice: while (ocifetch($stmt)) { .... }
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
7
by: Matthias Kwiedor | last post by:
Hi@all! I have a app (c#) where i load up a external dll (managed code from c#) with a small arraylist and hashtable in two routines (about 40000 objects in each arraylist and hashtable). If...
5
by: Vijay Ram | last post by:
Hi All, Is there any way to get the exact CPU Usage which is shown in Task Manager. Any code snippet or ideas will be appreciated. Thanx in advance, Vijay
4
by: Paul | last post by:
Hi all Please read my previous post here if this interests you: ...
1
by: =?Utf-8?B?UmF2aQ==?= | last post by:
How to fetch the CPU and Memory usage of IIS in C#? Thank you in advance. Regards, Ravi
0
by: Oli Schacher | last post by:
Hi all I wrote a multithreaded script that polls mails from several pop/imap accounts. To fetch the messages I'm using the getmail classes ( http://pyropus.ca/software/getmail/ ) , those...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.