Performance Counter Programming Architecture

The PerformanceCounter component uses these portions of the Microsoft .NET Framework namespaces:

PerformanceCounter Namespace

Performance Counter Namespace

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).

Key Performance Counter Classes

The following are the major classes associated with PerformanceCounter components:

  • System.Diagnostics.PerformanceCounter — the base class used to create PerformanceCounter components and interact with their values.

  • 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.

Key Programming Elements in the PerformanceCounter and PerformanceCounterCategory Classes

You can use the following methods to interact with performance counters:

See Also


How to: Add or Remove References in Visual Studio (Visual Basic)


Introduction to Monitoring Performance Thresholds