PerformanceCounterCategory.Create Method (String, String, CounterCreationDataCollection)

Note: This API is now obsolete.

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

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

[ObsoleteAttribute("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 PerformanceCounterCategory Create(
	string categoryName,
	string categoryHelp,
	CounterCreationDataCollection counterData
)

Parameters

categoryName
Type: System.String
The name of the custom performance counter category to create and register with the system.
categoryHelp
Type: System.String
A description of the custom category.
counterData
Type: System.Diagnostics.CounterCreationDataCollection
A CounterCreationDataCollection that specifies the counters to create as part of the new category.

Return Value

Type: System.Diagnostics.PerformanceCounterCategory
A PerformanceCounterCategory that is associated with the new custom category, or performance object.

ExceptionCondition
ArgumentException

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.

ArgumentNullException

The categoryName parameter is null.

InvalidOperationException

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

Win32Exception

A call to an underlying system API failed.

UnauthorizedAccessException

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

NoteNote

To read performance counters 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.

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 = 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);

}


.NET Framework

Supported in: 1.1, 1.0
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

.NET Framework Client Profile

Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft