Performance Counters Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  1. Create a custom performance counter that can be written to.

    1. Open Server Explorer.

    2. Open the Servers node, open the server node for your computer, and then open the Performance Counters node.

    3. Right-click Performance Counters and click Create New Category.

    4. In the Performance Counter Builder Dialog Box, type Performance Counter Sample as the Category Name, and any description in the Category Description text box.

    5. Click the New button to add a new performance counter.

    6. Type a name and description for the counter. Choose NumberOfItems32 for the Type.

  2. Press F5 to run the project.

  3. Choose the custom performance counter you built earlier. Choose it by Category and Counter, and then use the buttons to increment and decrement the value.

Demonstrates

Tasks demonstrated include the following:

  • Listing categories   Performance counter categories are retrieved using the GetCategories method and displayed in a ComboBox control.

  • Listing counters   Performance counters are retrieved using the GetCounters method and displayed in a ComboBox control. Only the counters from the selected category are retrieved.

  • Retrieving data   The NextValue method is used to retrieve the current value of the selected counter.

  • Custom counters   The application only allows you to increment custom counters. A custom counter is defined as a counter where you cannot call the NextValue method.