473,395 Members | 1,681 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,395 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
Nov 17 '05 #1
5 1429
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.??
Nov 17 '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

Nov 17 '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
Nov 17 '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

Nov 17 '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
Nov 17 '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)) { .... }
2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
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
8
by: Evan Smith | last post by:
During a routine performance check using an event monitor, I discovered a class of query whose performance has me baffled. The monitor captured: SELECT * FROM EWM_CASE fetch first 1 rows only...
7
by: Bernard Lebel | last post by:
Hello, I'm stumbled at a serious problem, and quite frankly getting desparate. This is a rather long-winded one so I'll try to get straight to the point. I have this Python program, that...
10
by: scoonie999 | last post by:
I'm having a problem that I can't seem to find any solution for online. I'm using a cursor in a cobol program to fetch some data. I know for a fact that the select should return 2 rows. The...
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
7
by: Frank Swarbrick | last post by:
Is there a way to do a multi-row fetch in to a COBOL table with DB2/LUW? Apparently the following is supported in z/OS, but not LUW (or at least I couldn't get it to work): WORKING-STORAGE...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.