How Do I...Read from a performance counter?

Windows performance counters enable
your applications and components to publish, capture (read), and analyze the
performance data that applications, services, and drivers provide. You can use
this information to determine system bottlenecks and fine-tune system and
application performance. For example, you can use a performance counter to
track the number of orders processed per second or a system's processor
utilization. Using the common language runtime's PerformanceCounter
component, you can easily read performance data relevant to your
application, such as those mentioned above.

This sample illustrates how to read simple performance information from a
performance counter. It is a small console application that can be run from a
command prompt. The application takes three command line arguments. The first is
a performance object name (category). The second argument is the counter name.
The third argument is the counter instance name.

For example, in order to see the processor utilization on your machine run
the sample with the following command line arguments:

> PCRead.exe "Processor" "% Processor Time" "_Total"

You will see the processor utilization data updated every half-second.

In its simplest form, reading a performance counter involves:

Creating a new instance of a PerformanceCounter component and pointing it to an appropriate
performance counter: