CounterCreationDataCollection Constructor (CounterCreationDataCollection)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com 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
ArgumentNullException

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);
}
else
{
    Console.WriteLine("The category already exists");
}

.NET Framework
Available since 1.1
Return to top
Show: