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.
Note |
---|
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.
Note |
---|
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
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 How to: Access and Initialize Server Explorer/Database Explorer.
Locate and expand the Performance Counters node beneath it.
Locate the counter you want to add to your project, and then right-click it.
Click Add to Designer.
Configure your component. For more information, see How to: Configure PerformanceCounter Component Instances.
To create an instance of the PerformanceCounter component from the Toolbox
Access the Components tab of the Toolbox.
Select the PerformanceCounter icon and drag it to the designer surface for your form or component.
Configure your component. For more information, see How to: Configure PerformanceCounter Component Instances.
To create an instance of the PerformanceCounter component programmatically
Create an instance of the PerformanceCounter class in code. You code might look like this:
Dim myCounter As New System.Diagnostics.PerformanceCounter()
System.Diagnostics.PerformanceCounter myCounter = new System.Diagnostics.PerformanceCounter();
System.Diagnostics.PerformanceCounter myCounter = new System.Diagnostics.PerformanceCounter();
Configure any other necessary properties for your component. For more information, see How to: Configure PerformanceCounter Component Instances.
See Also
Tasks
How to: Configure PerformanceCounter Component Instances
Reference
How to: Access and Initialize Server Explorer/Database Explorer