Esta documentación está archivada y no tiene mantenimiento.

CounterCreationDataCollection.Remove (Método)

Actualización: noviembre 2007

Quita un objeto CounterCreationData de la colección.

Espacio de nombres:  System.Diagnostics
Ensamblado:  System (en System.dll)

public virtual void Remove(
	CounterCreationData value
)
public void Remove(
	CounterCreationData value
)
public function Remove(
	value : CounterCreationData
)

Parámetros

value
Tipo: System.Diagnostics.CounterCreationData
CounterCreationData que se va a quitar de la colección.

ExcepciónCondición
ArgumentNullException

value es null.

ArgumentException

value no es un objeto CounterCreationData.

O bien,

value no existe en la colección.

En el ejemplo siguiente se muestra cómo usar el método Remove para eliminar un objeto CounterCreationData de CounterCreationDataCollection.

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();
    // Add the 'CounterCreationData[]' to 'CounterCollection'.
    myCounterCollection.AddRange(myCounterCreationData);

    PerformanceCounterCategory.Create(myCategoryName,
       "Sample Category",
    PerformanceCounterCategoryType.SingleInstance, myCounterCollection);

    if (myCounterCreationData.Length > 0)
    {
        if (myCounterCollection.Contains(myCounterCreationData[0]))
        {
            myCounterCollection.Remove(myCounterCreationData[0]);
            Console.WriteLine("'{0}' counter is removed from the " +
               "CounterCreationDataCollection", myCounterCreationData[0].CounterName);
        }
    }
    else
    {
        Console.WriteLine("The counters does not exist");
    }
}
else
{
    Console.WriteLine("The category already exists");
}


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 = 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();
    // Add the 'CounterCreationData[]' to 'CounterCollection'.
    myCounterCollection.AddRange(myCounterCreationData);

    PerformanceCounterCategory.Create(myCategoryName,
        "Sample Category", myCounterCollection);

    for (int i = 0; i < numberOfCounters; i++) {
        myCounter = new PerformanceCounter(myCategoryName,
            myCounterCreationData[i].get_CounterName(), "", false);
    }
    // Remove an instance of 'CounterCreationData' from
    // 'CounterCollection'.
    if (myCounterCreationData.get_Length() > 0) {
        if (myCounterCollection.Contains(
            myCounterCreationData.get_Item(0))) {
            myCounterCollection.Remove(
                myCounterCreationData.get_Item(0));
            Console.WriteLine("'{0}' counter is removed from the " 
                + "CounterCreationDataCollection",
                myCounterCreationData[0].get_CounterName());
        }
    }
    else {
        Console.WriteLine("The counters does not exist");
    }
}
else {
    Console.WriteLine("The category already exists");
}


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

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
Mostrar: