Represents a performance object, which defines a category of performance counters.
Assembly: System (in System.dll)
Thetype exposes the following members.
|PerformanceCounterCategory()||Initializes a new instance of the class, leaves the CategoryName property empty, and sets the MachineName property to the local computer.|
|PerformanceCounterCategory(String)||Initializes a new instance of the class, sets the CategoryName property to the specified value, and sets the MachineName property to the local computer.|
|PerformanceCounterCategory(String, String)||Initializes a new instance of the class and sets the CategoryName and MachineName properties to the specified values.|
|CounterExists(String)||Determines whether the specified counter is registered to this category, which is indicated by the CategoryName and MachineName properties.|
|CounterExists(String, String)||Determines whether the specified counter is registered to the specified category on the local computer.|
|CounterExists(String, String, String)||Determines whether the specified counter is registered to the specified category on a remote computer.|
|Create(String, String, CounterCreationDataCollection)||Obsolete. Registers the custom performance counter category containing the specified counters on the local computer.|
|Create(String, String, PerformanceCounterCategoryType, CounterCreationDataCollection)||Registers the custom performance counter category containing the specified counters on the local computer.|
|Create(String, String, String, String)||Obsolete. Registers a custom performance counter category containing a single counter of type NumberOfItems32 on the local computer.|
|Create(String, String, PerformanceCounterCategoryType, String, String)||Registers the custom performance counter category containing a single counter of type NumberOfItems32 on the local computer.|
|Delete||Removes the category and its associated counters from the local computer.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Exists(String)||Determines whether the category is registered on the local computer.|
|Exists(String, String)||Determines whether the category is registered on the specified computer.|
|GetCategories()||Retrieves a list of the performance counter categories that are registered on the local computer.|
|GetCategories(String)||Retrieves a list of the performance counter categories that are registered on the specified computer.|
|GetCounters()||Retrieves a list of the counters in a performance counter category that contains exactly one instance.|
|GetCounters(String)||Retrieves a list of the counters in a performance counter category that contains one or more instances.|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetInstanceNames||Retrieves the list of performance object instances that are associated with this category.|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|InstanceExists(String)||Determines whether the specified performance object instance exists in the category that is identified by this object's CategoryName property.|
|InstanceExists(String, String)||Determines whether a specified category on the local computer contains the specified performance object instance.|
|InstanceExists(String, String, String)||Determines whether a specified category on a specified computer contains the specified performance object instance.|
|ReadCategory||Reads all the counter and performance object instance data that is associated with this performance counter category.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
Creating or deleting a performance counter requires synchronization of the underlying code by using a named mutex. If a highly privileged application locks the named mutex, attempts to create or delete a performance counter causes the application to stop responding until the lock is released. To help avoid this problem, never grant UnmanagedCode permission to untrusted code. In addition, UnmanagedCode permission potentially allows other permissions to be bypassed and should only be granted to highly trusted code.
The instance's CategoryName property is displayed in the Performance Object field of the Performance Viewer application's Add Counter dialog box.
The class provides several methods for interacting with counters and categories on the computer. The Create methods enable you to define custom categories. The Delete method provides a way to remove categories from the computer. The GetCategories method enables you to view the list of categories, while ReadCategory retrieves all the counter and instance data associated with a single category.
A performance counter publishes performance data about an application. Categories include physical components (such as processors, disks, and memory) and system objects (such as processes and threads). System counters that are related to the same performance object are grouped into a category that indicates their common focus. When you create an instance of the PerformanceCounter class, you first indicate the category with which the component will interact, and then you choose a counter from that category.
For example, one Windows counter category is the Memory category. System counters within this category track memory data such as the number of bytes available and the number of bytes cached. If you wanted to work with the bytes cached in your application, you would create an instance of the PerformanceCounter component, connect it to the Memory category, and then pick the appropriate counter (in this case, Cached Bytes) from that category.
Although your system makes many more counter categories available, the categories that you will probably interact with most frequently are the Cache, Memory, Objects, PhysicalDisk, Process, Processor, Server, System, and Thread categories.
The RemoveInstance method in the PerformanceCounter class will release the counter and, if the reuse option is selected for that category, the instance of the counter will be reused. This could cause a race condition if another process or even another part of the code is trying to write to the counter instance.
It is strongly recommended that new performance counter categories be created during the installation of the application, not during the execution of the application. This allows time for the operating system to refresh its list of registered performance counter categories. If the list has not been refreshed, the attempt to use the category will fail.
Performance counter categories installed with the .NET Framework 2.0 use separate shared memory, with each performance counter category having its own memory. You can specify the size of separate shared memory by creating a DWORD named FileMappingSize in the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<category name>\Performance. The FileMappingSize value is set to the shared memory size of the category. The default size is 131072 decimal. If the FileMappingSize value is not present, the fileMappingSize attribute value for the performanceCounters element specified in the Machine.config file is used, causing additional overhead for configuration file processing. You can realize a performance improvement for application startup by setting the file mapping size in the registry. For more information about the file mapping size, see <performanceCounters> Element.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.
The following code example determines whether a PerformanceCounter and its exist on the local computer or on another computer. If these objects do not exist on the local computer, the example optionally creates them. It uses the Exists method to determine whether the exists. If the does not exist and no counter name is specified, or if the computer is a remote machine, the example exits.
If a PerformanceCounter name is provided, the example uses the CounterExists method and displays the result to the user. If the PerformanceCounter does not exist, the user can delete and re-create the with the new PerformanceCounter. If the user does so, the category is deleted using the Delete method.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.