Export (0) Print
Expand All

How to: Create PerformanceCounter Component Instances 

You create an instance of the PerformanceCounter component when you want to make available performance data about your application or monitor the performance of resources on your system. PerformanceCounter components allow you to connect to existing performance counters, write values to custom counters, and react to values the counters receive.

PerformanceCounter components have no visual user interface. If you add an instance of the PerformanceCounter component to a visual designer (such as the Windows Forms Designer), the component appears in a small area below the bottom border of the form. This is known as the component tray and acts as a place to display all of the non-visual items associated with the form.

NoteNote

Nonvisual classes that inherit from Component support a visual design surface, similar to the component tray, on which your PerformanceCounter component and other components are arranged. The arrangement of items on this designer is not important, as the interface you see will never be displayed to the application's end users.

There are several ways you can create an instance of the PerformanceCounter component:

  • You can locate the counter you want in Server Explorer and add it to your designer, creating an instance of the PerformanceCounter component that is preconfigured to point to that counter.

  • You can drag an instance of the PerformanceCounter component from the Components tab of the Toolbox to a form or other designer.

  • You can create an instance of the PerformanceCounter component in code.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To create an instance of the PerformanceCounter components from Server Explorer

  1. In Server Explorer, expand the Servers node, and then expand the node for the server you want to view.

    NoteNote

    If the server you want is not listed, you need to add it. For more information, see How to: Access and Initialize Server Explorer/Database Explorer.

  2. Locate and expand the Performance Counters node beneath it.

  3. Locate the counter you want to add to your project, and then right-click it.

  4. Click Add to Designer.

  5. Configure your component. For more information, see How to: Configure PerformanceCounter Component Instances.

To create an instance of the PerformanceCounter component from the Toolbox

  1. Access the Components tab of the Toolbox.

  2. Select the PerformanceCounter icon and drag it to the designer surface for your form or component.

  3. Configure your component. For more information, see How to: Configure PerformanceCounter Component Instances.

To create an instance of the PerformanceCounter component programmatically

  1. Create an instance of the PerformanceCounter class in code. You code might look like this:

    System.Diagnostics.PerformanceCounter myCounter =     new System.Diagnostics.PerformanceCounter();
    
    System.Diagnostics.PerformanceCounter myCounter =
       new System.Diagnostics.PerformanceCounter();
    
  2. Configure any other necessary properties for your component. For more information, see How to: Configure PerformanceCounter Component Instances.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft