CounterCreationDataCollection Constructor (CounterCreationDataCollection)

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

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

public CounterCreationDataCollection (
	CounterCreationDataCollection value
)
public CounterCreationDataCollection (
	CounterCreationDataCollection value
)
public function CounterCreationDataCollection (
	value : CounterCreationDataCollection
)

Parameters

value

A CounterCreationDataCollection that holds CounterCreationData instances with which to initialize this CounterCreationDataCollection.

Exception typeCondition

ArgumentNullException

value is a null reference (Nothing in Visual Basic).

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",
      myNewCounterCollection);

   for(int i = 0; i < numberOfCounters; i++)
   {
      myCounter = new PerformanceCounter(myCategoryName,
         myCounterCreationData[i].CounterName, "", false);
   }
   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");
}

String myCategoryName;
int numberOfCounters;
Console.Write("Enter the number of counters : ");
numberOfCounters = Int32.Parse(Console.ReadLine());
CounterCreationData myCounterCreationData[] = new 
    CounterCreationData[numberOfCounters];
for (int i = 0; i < numberOfCounters; i++) {
    Console.Write("Enter the counter name for {0} counter : ",
        System.Convert.ToString(i));
    myCounterCreationData.set_Item(i, new CounterCreationData());
    myCounterCreationData[i].set_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", myNewCounterCollection);

    for (int i = 0; i < numberOfCounters; i++) {
        myCounter = new PerformanceCounter(myCategoryName,
            myCounterCreationData[i].get_CounterName(), "", false);
    }
    Console.WriteLine("The list of counters in "
        + "'CounterCollection' are : ");
    for (int i = 0; i < myNewCounterCollection.get_Count(); i++) {
        Console.WriteLine("Counter {0} is '{1}'", 
            System.Convert.ToString(i), 
            myNewCounterCollection.get_Item(i).get_CounterName());
    }
}
else {
    Console.WriteLine("The category already exists");
}

String myCategoryName;
int numberOfCounters;
Console.Write("Enter the number of counters : ");
numberOfCounters = Int32.Parse(Console.ReadLine());
CounterCreationData myCounterCreationData[] = new 
    CounterCreationData[numberOfCounters];
for (int i = 0; i < numberOfCounters; i++) {
    Console.Write("Enter the counter name for {0} counter : ",
        System.Convert.ToString(i));
    myCounterCreationData[i] = new CounterCreationData();
    myCounterCreationData[i].set_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", myNewCounterCollection);

    for (int i = 0; i < numberOfCounters; i++) {
        myCounter = new PerformanceCounter(myCategoryName, 
            myCounterCreationData[i].get_CounterName(), "", false);
    }
    Console.WriteLine("The list of counters in "
        + "'CounterCollection' are : ");
    for (int i = 0; i < myNewCounterCollection.get_Count(); i++) {
        Console.WriteLine("Counter {0} is '{1}'", 
            System.Convert.ToString(i), 
            myNewCounterCollection.get_Item(i).get_CounterName());
    }
}
else {
    Console.WriteLine("The category already exists");
}

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: