CounterCreationData Constructor (String, String, PerformanceCounterType)
Collapse the table of content
Expand the table of content

CounterCreationData Constructor (String, String, PerformanceCounterType)

Initializes a new instance of the CounterCreationData class, to a counter of the specified type, using the specified counter name and Help strings.

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

public CounterCreationData(
	string counterName,
	string counterHelp,
	PerformanceCounterType counterType


Type: System.String
The name of the counter, which must be unique within its category.
Type: System.String
The text that describes the counter's behavior.
Type: System.Diagnostics.PerformanceCounterType
A PerformanceCounterType that identifies the counter's behavior.


You have specified a value for counterType that is not a member of the PerformanceCounterType enumeration.


counterHelp is null.

The following code example shows how to create an instance of the CounterCreationData class, and pass in parameters to set the CounterHelp, CounterName and CounterType properties of the object when it is initialized.

using System;
using System.Diagnostics;

namespace MyDiagnostics
    class MyCounterCreationData
        static void Main()
            CounterCreationDataCollection myCol =
                                       new CounterCreationDataCollection();

            // Create two custom counter objects.
            CounterCreationData myCounter1 = new CounterCreationData("Counter1",
               "First custom counter", PerformanceCounterType.CounterDelta32);

            CounterCreationData myCounter2 = new CounterCreationData();

            // Set the properties of the 'CounterCreationData' object.
            myCounter2.CounterName = "Counter2";
            myCounter2.CounterHelp = "Second custom counter";
            myCounter2.CounterType = PerformanceCounterType.NumberOfItemsHEX32;

            // Add custom counter objects to CounterCreationDataCollection.

            if (PerformanceCounterCategory.Exists("New Counter Category"))
                PerformanceCounterCategory.Delete("New Counter Category");

            // Bind the counters to a PerformanceCounterCategory.
            PerformanceCounterCategory myCategory =
                  PerformanceCounterCategory.Create("New Counter Category", "Category Help",
                PerformanceCounterCategoryType.SingleInstance, myCol);

            Console.WriteLine("Counter Information:");
            Console.WriteLine("Category Name: " + myCategory.CategoryName);
            for (int i = 0; i < myCol.Count; i++)
                // Display the properties of the CounterCreationData objects.
                Console.WriteLine("CounterName : " + myCol[i].CounterName);
                Console.WriteLine("CounterHelp : " + myCol[i].CounterHelp);
                Console.WriteLine("CounterType : " + myCol[i].CounterType);

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 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.

Community Additions

© 2016 Microsoft