Export (0) Print
Expand All

CounterCreationDataCollection Constructor (CounterCreationData[])

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

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

public CounterCreationDataCollection(
	CounterCreationData[] value
)

Parameters

value
Type: System.Diagnostics.CounterCreationData[]

An array of CounterCreationData instances with which to initialize this CounterCreationDataCollection.

ExceptionCondition
ArgumentNullException

value is null.

The following example demonstrates how to create a CounterCreationDataCollection object by using a CounterCreationData array.

string myCategoryName;
int numberOfCounters;
Console.Write("Enter the category Name : ");
myCategoryName = Console.ReadLine();
// Check if the category already exists or not. 
if (!PerformanceCounterCategory.Exists(myCategoryName))
{
    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);
    // Create the category.
    PerformanceCounterCategory.Create(myCategoryName,
       "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myCounterCollection);

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

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft