Export (0) Print
Expand All

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

Note   Nonvisual classes that inherit from System.ComponentModel.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.

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.
    Note   If the server you want is not listed, you need to add it. For more information, see Accessing and Initializing Server Explorer.
    Note   The Servers node of Server Explorer is not available in the Standard Edition of Visual Basic and Visual C# .NET. For more information, see Visual Basic Standard Edition Features or Visual C# Standard Edition Features.
  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 Configuring 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 Configuring 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:
    ' Visual Basic
    Dim myCounter As New System.Diagnostics.PerformanceCounter()
    
    // C#
    System.Diagnostics.PerformanceCounter myCounter =
       new System.Diagnostics.PerformanceCounter();
    
  2. Configure any other necessary properties for your component. For more information, see Configuring PerformanceCounter Component Instances.

See Also

Configuring PerformanceCounter Component Instances | Accessing and Initializing Server Explorer

Show:
© 2014 Microsoft