CounterCreationDataCollection Constructor (CounterCreationDataCollection)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the CounterCreationDataCollection class by using the specified collection of CounterCreationData instances.

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

public CounterCreationDataCollection(
	CounterCreationDataCollection value

Exception Condition

value is null.

The following example demonstrates how to create a CounterCreationDataCollection object by using CounterCreationData objects from another CounterCreationDataCollection.

string myCategoryName;
int numberOfCounters;
Console.Write("Enter the number of counters : ");
numberOfCounters = int.Parse(Console.ReadLine());
CounterCreationData[] myCounterCreationData =
   new CounterCreationData[numberOfCounters];
for (int i = 0; i < numberOfCounters; i++)
    Console.Write("Enter the counter name for {0} counter : ", i);
    myCounterCreationData[i] = new CounterCreationData();
    myCounterCreationData[i].CounterName = Console.ReadLine();
CounterCreationDataCollection myCounterCollection =
   new CounterCreationDataCollection(myCounterCreationData);
Console.Write("Enter the category Name:");
myCategoryName = Console.ReadLine();
// Check if the category already exists or not.
if (!PerformanceCounterCategory.Exists(myCategoryName))
    CounterCreationDataCollection myNewCounterCollection =
       new CounterCreationDataCollection(myCounterCollection);
    PerformanceCounterCategory.Create(myCategoryName, "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myNewCounterCollection);

    Console.WriteLine("The list of counters in 'CounterCollection' are : ");
    for (int i = 0; i < myNewCounterCollection.Count; i++)
        Console.WriteLine("Counter {0} is '{1}'", i, myNewCounterCollection[i].CounterName);
    Console.WriteLine("The category already exists");

.NET Framework
Available since 1.1
Return to top