473,396 Members | 1,775 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,396 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 20 '05 #1
7 13914
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 20 '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 20 '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 20 '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 20 '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 20 '05 #6
Cor
This is an Of Thread message about an old question about SQL and webpage
special for Fergus.

Hi Fergus,
Did you remember that problem with images in a SQL database that had to be
shown on a Webform, from which we thought the solution would be
MemoryStream. That does not work because there is no control that can accept
a byte(). (For images only Url's are right).

That example that was retruned and that we saw, was given everywhere in the
asp.net group, but that gives a bad uncontrolled picture on a page.

I did look everywhere but all examples on Internet that I did found where
memorystream and picturebox (window form).

But I found in the in asp.group a hind how to make it with script. But with
script and than you can call a page. I did make it for vb.net. language now
and it works nice. So when there is a next one with that question, wait for
me and sign me in.

Cor
Nov 20 '05 #7
Hi Cor,

|| Did you remember that problem with images in a SQL database
|| that had to be shown on a Webform, from which we thought the
|| solution would be MemoryStream.

I hope we didn't think that!! :-) The MemoryStream was to avoid having to
use a file on the server. Getting the data to the web page was the main issue,
and for which we had no solution at the time.

|| That does not work because there is no control that can accept a
byte().
|| For images only Url's are right).

Yes, you have to have a Uri that requests an image and set the response
content type appropriately for the image data.

|| The example that was returned and that we saw, was given
|| everywhere in the asp.net group, but that gives a bad
|| uncontrolled picture on a page.

That's interesting. What sort of bad picture?

|| I did make it for vb.net. language now and it works nice.

That's even more interesting. :-)

Could you send me a copy ? And/or you could post it to the end of the
original thread. (I'd see it there. I keep threads marked for ages - just in
case). And a copy to the asp group if they aren't linked to that thread.

Cheers,
Fergus
Nov 20 '05 #8

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.