Performance Counter Programming Architecture
The PerformanceCounter component uses these portions of the Microsoft .NET Framework namespaces:
When you add an instance of the PerformanceCounter component to your application, Visual Studio automatically creates the references and import statements you need to access the namespace and classes. However, if you are creating your PerformanceCounter instances in code, you might need to create a reference to System.dll and add a statement to your project importing (in Visual Basic) or using (in C#) the appropriate namespace (such as System.Diagnostics).
For more information on adding and removing project references, see How to: Add or Remove References in Visual Studio (Visual Basic).
The following are the major classes associated with PerformanceCounter components:
PerformanceCounterCategory — provides access to the categories for which performance counters exist on a server and all of their corresponding properties and methods. You use methods in this class to create new categories and custom counters, to verify that categories and counters exist, and to read the existing counters in a category.
System.Diagnostics.CounterCreationData — used to create multiple counters for a category; allows you to explicitly choose the counter type for each counter you create.
System.Diagnostics.InstanceData — used to retrieve multiple instances of a counter and all of their corresponding properties and methods.
You can use the following methods to interact with performance counters:
Use the Create method on the PerformanceCounterCategory class to define a new category containing one or more counters. Similarly, the Delete method removes a user-defined category and the counters it contains.
Use the Increment method or IncrementBy method on the PerformanceCounter class to increment a counter value by one or by the specified integer and to return the new value of the counter. Similarly, you can use the Decrement method to reduce a counter's value.