.NET Framework: Reading and Writing to Performance Counters

This sample shows some how to read from and write to Performance Counters using Visual Basic.NET. These counters can be used to track the performance of various parts of the operating system and .NET applications.

Featured Highlights:

This how-to demonstrates how to read from and write to performance counters. Concepts demonstrated are:

Requirements:

Microsoft Visual Studio.NET Professional or greater.
Windows 2000 or Windows XP.

Running the Sample:

To run the sample:

  1. Doubleclick the How-To Reading and Writing to Performance Counters.sln file. 
  2. Create a custom performance counter that can be written to. Creating an example counter is outlined below.
  3. Explore selecting and reading from the built-in performance counters.
  4. Select the custom performance counter you build earlier. Select it by Category and Counter, then use the increment and decrement buttons to increment and decrement the value.
  5. Explore Performance Counters further by creating more custom performance counters of other types, including "RateOfCountsPerSecond32" which measures the number of increments that occur in running one-second intervals.

See Also:

Introduction to Monitoring Performance Thresholds, System.Diagnostics.PerformanceCounter, System.Diagnostics Namespace