Szerkesztés

Megosztás a következőn keresztül:


PerformanceCounterCategory.Create Method

Definition

Registers a custom performance counter category and one or more counters with the system.

Overloads

Create(String, String, String, String)
Obsolete.
Obsolete.
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.

Create(String, String, CounterCreationDataCollection)
Obsolete.
Obsolete.
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)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

Caution

This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.

Caution

This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. http://go.microsoft.com/fwlink/?linkid=14202

Caution

This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead. https://go.microsoft.com/fwlink/?linkid=14202

Registers a custom performance counter category containing a single counter of type NumberOfItems32 on the local computer.

public:
 static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::String ^ counterName, System::String ^ counterHelp);
[System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.")]
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, string counterName, string counterHelp);
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, string counterName, string counterHelp);
[System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, string counterName, string counterHelp);
[System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.  https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, string counterName, string counterHelp);
[<System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.")>]
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, string counterName, string counterHelp) instead.  https://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * string * string -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, counterName As String, counterHelp As String) As PerformanceCounterCategory

Parameters

categoryName
String

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

categoryHelp
String

A description of the custom category.

counterName
String

The name of a new counter, of type NumberOfItems32, to create as part of the new category.

counterHelp
String

A description of the counter that is associated with the new custom category.

Returns

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

Attributes

Exceptions

counterName is null or is an empty string ("").

-or-

The counter that is specified by counterName already exists.

-or-

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

The category already exists on the local computer.

categoryName is null.

-or-

counterHelp is null.

A call to an underlying system API failed.

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

Examples

The following code example creates a PerformanceCounterCategory and single PerformanceCounter with help text for each, using the Create(String, String, String, String) method.

public static void Main(string[] args)
{
    string categoryName = "";
    string counterName = "";
    string categoryHelp = "";
    string counterHelp = "";
    PerformanceCounterCategory pcc;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        counterName = args[1];
        categoryHelp = args[2];
        counterHelp = args[3];
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    Console.WriteLine("Category name: \"{0}\"", categoryName);
    Console.WriteLine("Category help: \"{0}\"", categoryHelp);
    Console.WriteLine("Counter name:  \"{0}\"", counterName);
    Console.WriteLine("Counter help:  \"{0}\"", counterHelp);

    // Use the Create overload that creates a single counter.
    try
    {
        pcc = PerformanceCounterCategory.Create(categoryName, categoryHelp, counterName, counterHelp);
        Console.WriteLine("Category \"{0}\" created.", pcc.CategoryName);
    }
    catch(Exception ex)
    {
        Console.WriteLine("Unable to create the above category and counter:" + "\n" + ex.Message);
    }
}
Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim counterName As String = ""
    Dim categoryHelp As String = ""
    Dim counterHelp As String = ""
    Dim pcc As PerformanceCounterCategory

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        counterName = args(1)
        categoryHelp = args(2)
        counterHelp = args(3)
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    Console.WriteLine("Category name: ""{0}""", categoryName)
    Console.WriteLine("Category help: ""{0}""", categoryHelp)
    Console.WriteLine("Counter name:  ""{0}""", counterName)
    Console.WriteLine("Counter help:  ""{0}""", counterHelp)

    ' Use the Create overload that creates a single counter.
    Try
        pcc = PerformanceCounterCategory.Create( _
            categoryName, categoryHelp, counterName, counterHelp)
        Console.WriteLine("Category ""{0}"" created.", pcc.CategoryName)

    Catch ex As Exception
        Console.WriteLine( _
            "Unable to create the above category and counter:" & _
            vbCrLf & ex.Message)
    End Try
End Sub

Remarks

Note

To read performance counters from a non-interactive logon session in Windows Vista and later, 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 and later, add yourself to the Performance Monitor Users group.

In Windows Vista and later, 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.

See also

Applies to

Create(String, String, PerformanceCounterCategoryType, String, String)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

Registers the custom performance counter category containing a single counter of type NumberOfItems32 on the local computer.

public:
 static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::Diagnostics::PerformanceCounterCategoryType categoryType, System::String ^ counterName, System::String ^ counterHelp);
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, System.Diagnostics.PerformanceCounterCategoryType categoryType, string counterName, string counterHelp);
static member Create : string * string * System.Diagnostics.PerformanceCounterCategoryType * string * string -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, categoryType As PerformanceCounterCategoryType, counterName As String, counterHelp As String) As PerformanceCounterCategory

Parameters

categoryName
String

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

categoryHelp
String

A description of the custom category.

categoryType
PerformanceCounterCategoryType

One of the PerformanceCounterCategoryType values specifying whether the category is MultiInstance, SingleInstance, or Unknown.

counterName
String

The name of a new counter to create as part of the new category.

counterHelp
String

A description of the counter that is associated with the new custom category.

Returns

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

Exceptions

counterName is null or is an empty string ("").

-or-

The counter that is specified by counterName already exists.

-or-

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

The category already exists on the local computer.

categoryName is null.

-or-

counterHelp is null.

A call to an underlying system API failed.

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

Examples

The following code example shows the use of the Create method. The example shows how to create a custom, single instance performance counter category.

Console.WriteLine("Creating Inventory custom counter");
if (!PerformanceCounterCategory.Exists("Inventory"))
    PerformanceCounterCategory.Create("Inventory",
        "Truck inventory",
        PerformanceCounterCategoryType.SingleInstance,
        "Trucks", "Number of trucks on hand");
Console.WriteLine("Creating Inventory custom counter")
If Not PerformanceCounterCategory.Exists("Inventory") Then
    PerformanceCounterCategory.Create("Inventory", "Truck inventory", PerformanceCounterCategoryType.SingleInstance, "Trucks", "Number of trucks on hand")
End If

Remarks

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 .NET Framework 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.

Note

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.

Note

To read performance counters from a non-interactive logon session in Windows Vista and later, 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 and later, add yourself to the Performance Monitor Users group.

In Windows Vista and later, 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.

See also

Applies to

Create(String, String, CounterCreationDataCollection)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

Caution

This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.

Caution

This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. http://go.microsoft.com/fwlink/?linkid=14202

Caution

This method has been deprecated. Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead. https://go.microsoft.com/fwlink/?linkid=14202

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

public:
 static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::Diagnostics::CounterCreationDataCollection ^ counterData);
[System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.")]
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
[System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
[System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.  https://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, System.Diagnostics.CounterCreationDataCollection counterData);
[<System.Obsolete("This overload of PerformanceCounterCategory.Create has been deprecated. Use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.")>]
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
[<System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.PerformanceCounterCategory.Create(string categoryName, string categoryHelp, PerformanceCounterCategoryType categoryType, CounterCreationDataCollection counterData) instead.  https://go.microsoft.com/fwlink/?linkid=14202")>]
static member Create : string * string * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, counterData As CounterCreationDataCollection) As PerformanceCounterCategory

Parameters

categoryName
String

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

categoryHelp
String

A description of the custom category.

counterData
CounterCreationDataCollection

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

Returns

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

Attributes

Exceptions

A counter name that is specified within the counterData collection is null or an empty string ("").

-or-

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

-or-

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

The categoryName parameter is null.

The category already exists on the local computer.

-or-

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 has to 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.

Examples

The following code example determines whether a PerformanceCounterCategory object named "orders" exists. If not, it creates the PerformanceCounterCategory object by using a CounterCreationDataCollection object that contains two performance counters.

if (  !PerformanceCounterCategory::Exists( "Orders" ) )
{
   CounterCreationData^ milk = gcnew CounterCreationData;
   milk->CounterName = "milk";
   milk->CounterType = PerformanceCounterType::NumberOfItems32;

   CounterCreationData^ milkPerSecond = gcnew CounterCreationData;
   milkPerSecond->CounterName = "milk orders/second";
   milkPerSecond->CounterType = PerformanceCounterType::RateOfCountsPerSecond32;

   CounterCreationDataCollection^ ccds = gcnew CounterCreationDataCollection;
   ccds->Add( milkPerSecond );
   ccds->Add( milk );
   PerformanceCounterCategory::Create( "Orders", "Number of processed orders", ccds );
}
if (!PerformanceCounterCategory.Exists("Orders"))
{
    CounterCreationData milk = new CounterCreationData();
    milk.CounterName = "milk";
    milk.CounterType = PerformanceCounterType.NumberOfItems32;

    CounterCreationData milkPerSecond = new CounterCreationData();
    milkPerSecond.CounterName = "milk orders/second";
    milkPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;

    CounterCreationDataCollection ccds = new CounterCreationDataCollection();
    ccds.Add(milkPerSecond);
    ccds.Add(milk);

    PerformanceCounterCategory.Create("Orders", "Number of processed orders",
        PerformanceCounterCategoryType.SingleInstance, ccds);
}
If Not PerformanceCounterCategory.Exists("Orders") Then        
    Dim milk As New CounterCreationData()
    milk.CounterName = "milk"
    milk.CounterType = PerformanceCounterType.NumberOfItems32
    
    Dim milkPerSecond As New CounterCreationData()
    milkPerSecond.CounterName = "milk orders/second"
    milkPerSecond.CounterType = PerformanceCounterType.RateOfCountsPerSecond32
    
    Dim ccds As New CounterCreationDataCollection()
    ccds.Add(milkPerSecond)
    ccds.Add(milk)
    
    PerformanceCounterCategory.Create("Orders", "Number of processed orders", _
           PerformanceCounterCategoryType.SingleInstance, ccds)
End If

Remarks

Note

To read performance counters from a non-interactive logon session in Windows Vista and later, 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 and later, add yourself to the Performance Monitor Users group.

In Windows Vista and later, 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.

See also

Applies to

Create(String, String, PerformanceCounterCategoryType, CounterCreationDataCollection)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

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

public:
 static System::Diagnostics::PerformanceCounterCategory ^ Create(System::String ^ categoryName, System::String ^ categoryHelp, System::Diagnostics::PerformanceCounterCategoryType categoryType, System::Diagnostics::CounterCreationDataCollection ^ counterData);
public static System.Diagnostics.PerformanceCounterCategory Create (string categoryName, string categoryHelp, System.Diagnostics.PerformanceCounterCategoryType categoryType, System.Diagnostics.CounterCreationDataCollection counterData);
static member Create : string * string * System.Diagnostics.PerformanceCounterCategoryType * System.Diagnostics.CounterCreationDataCollection -> System.Diagnostics.PerformanceCounterCategory
Public Shared Function Create (categoryName As String, categoryHelp As String, categoryType As PerformanceCounterCategoryType, counterData As CounterCreationDataCollection) As PerformanceCounterCategory

Parameters

categoryName
String

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

categoryHelp
String

A description of the custom category.

counterData
CounterCreationDataCollection

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

Returns

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

Exceptions

A counter name that is specified within the counterData collection is null or an empty string ("").

-or-

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

-or-

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

categoryName is null.

-or-

counterData is null.

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

The category already exists on the local computer.

-or-

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.

Examples

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();
ccds.Add(data1);
ccds.Add(data2);
Console.WriteLine("Creating Orders custom counter.");
if (!PerformanceCounterCategory.Exists("Orders"))
    PerformanceCounterCategory.Create("Orders",
        "Processed orders",
        PerformanceCounterCategoryType.MultiInstance,
        ccds);
Dim data1 As New CounterCreationData("Trucks", "Number of orders", PerformanceCounterType.NumberOfItems32)
Dim data2 As New CounterCreationData("Rate of sales", "Orders/second", PerformanceCounterType.RateOfCountsPerSecond32)
Dim ccds As New CounterCreationDataCollection()
ccds.Add(data1)
ccds.Add(data2)
Console.WriteLine("Creating Orders custom counter.")
If Not PerformanceCounterCategory.Exists("Orders") Then
    PerformanceCounterCategory.Create("Orders", "Processed orders", PerformanceCounterCategoryType.MultiInstance, ccds)
End If

Remarks

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 .NET Framework 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.

Note

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.

Note

To read performance counters from a non-interactive logon session in Windows Vista and later, 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 and later, add yourself to the Performance Monitor Users group.

In Windows Vista and later, 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.

See also

Applies to