PerformanceCounterCategory.Create Method (String, String, PerformanceCounterCategoryType, CounterCreationDataCollection)

Registers the custom performance counter category containing the specified counters on the local computer.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

public static PerformanceCounterCategory Create (
	string categoryName,
	string categoryHelp,
	PerformanceCounterCategoryType categoryType,
	CounterCreationDataCollection counterData
public static PerformanceCounterCategory Create (
	String categoryName, 
	String categoryHelp, 
	PerformanceCounterCategoryType categoryType, 
	CounterCreationDataCollection counterData
public static function Create (
	categoryName : String, 
	categoryHelp : String, 
	categoryType : PerformanceCounterCategoryType, 
	counterData : CounterCreationDataCollection
) : PerformanceCounterCategory
Not applicable.



The name of the custom performance counter category to create and register with the system.


A description of the custom category.


One of the PerformanceCounterCategoryType values.


A CounterCreationDataCollection that specifies the counters to create as part of the new category.

Return Value

A PerformanceCounterCategory that is associated with the new custom category, or performance object.

Exception typeCondition


A counter name that is specified within the counterData collection is a null reference (Nothing in Visual Basic) or an empty string ("").


A counter that is specified within the counterData collection already exists.


counterName has invalid syntax. It might contain backslash characters ("\") or have length greater than 80 characters.


categoryName is a null reference (Nothing in Visual Basic).


counterData is a null reference (Nothing in Visual Basic).


categoryType value is outside of the range of the following values: MultiInstance, SingleInstance, or Unknown.


The category already exists on the local computer.


The layout of the counterData collection is incorrect for base counters. A counter of type AverageCount64, AverageTimer32, CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns, CounterMultiTimer100NsInverse, RawFraction, SampleFraction, or SampleCounter must be immediately followed by one of the base counter types (AverageBase, MultiBase, RawBase, or SampleBase).


A call to an underlying system API failed.


Code that is executing without administrative privileges attempted to read a performance counter.

The categoryType parameter specifies whether the performance counter category is single-instance or multi-instance. By default, a category is single-instance when it is created and becomes multi-instance when another instance is added. Categories are created when an application is set up, and instances are added at run time. In the .NET Framework versions 1.0 and 1.1, it is not necessary to know if a performance counter category is multi-instance or single-instance. In the Microsoft .NET Framework version 2.0, the PerformanceCounterCategoryType enumeration is used to indicate whether a performance counter can have multiple instances.

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.


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.


To read performance counters in Windows Vista, Windows XP Professional x64 Edition, or Windows Server 2003, you must either be a member of the Performance Monitor Users group or have administrative privileges.

To avoid having to elevate your privileges to access performance counters in Windows Vista, add yourself to the Performance Monitor Users group.

In Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses performance counters, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.

The following code example shows the use of the Create method. The example shows how to create a custom, multi-instance performance counter category for the number of orders per second.

CounterCreationData data1 = new CounterCreationData("Trucks",
    "Number of orders", PerformanceCounterType.NumberOfItems32);
CounterCreationData data2 = new CounterCreationData("Rate of sales",
    "Orders/second", PerformanceCounterType.RateOfCountsPerSecond32);
CounterCreationDataCollection ccds = new CounterCreationDataCollection();
Console.WriteLine("Creating Orders custom counter.");
if (!PerformanceCounterCategory.Exists("Orders"))
        "Processed orders",

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions