PerformanceCounter Class in VB.NET
In this article I will explain you about the PerformanceCounter Class in VB.NET.
We always measure the performance of our code
(applications, services, drivers, etc.) in the field in real time or in a
testing environment. Then we can diagnose problems and fix them in the future.
Performance counters enable us to publish, capture, and analyze the performance
data of running code. A performance graph is a two-dimensional plot with one
axis indicating time elapsed and the other reporting relevant relative or actual
The common language runtime (CLR) provides a PerformanceCounter class, with
which we can read and write performance data on computers running Windows NT,
2000, or XP. We need to call counters in which the performance data is placed.
The names of the counters are stored in the Windows registry along with the
counters' various settings. Every performance counter has a unique name and
location. Another attribute of a counter is its category (the performance object
for which the counter measures data). For example, the Processor performance
category has the % Processor Time performance counter object (and others), which
has the _Total performance counter instance (and others). Please use Performance
Monitor MMC if you have Windows NT, 2000, or XP installed (it's found on the
Administrative Tools menu) to discover other PerformanceCounter categories,
objects, and instances. PerformanceCounter class members are defined in Table
Table 21.8: PerformanceCounter Class Members
The example given below shows how we might use performance counters. In this
example we measure the total processing time with the Processor performance
Example of Using PerformanceCounter
Processor does not exist!")
% Processor Time does not exist!")
"% Processor Time",
' The raw value of a counter can be set in your applications as
' if the object is not read-only
myCounter.RawValue = 19
% Processor Time, _Total instance is READONLY!")
'CTRL+C' to quit...")
value of Processor, %Processor Time, _Total= "
instance does not exist!")
'CTRL+C' to quit...")
Hope this article would have helped you in understanding the PerformanceCounter
Class in VB.NET.