AddRange (Método) (CounterCreationDataCollection)
Collapse the table of content
Expand the table of content

CounterCreationDataCollection.AddRange (Método) (CounterCreationDataCollection)

Actualización: noviembre 2007

Agrega a la colección la colección especificada de instancias de CounterCreationData.

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

public void AddRange(
	CounterCreationDataCollection value
)
public void AddRange(
	CounterCreationDataCollection value
)
public function AddRange(
	value : CounterCreationDataCollection
)

Parámetros

value
Tipo: System.Diagnostics.CounterCreationDataCollection
Colección de instancias de CounterCreationData que se va a agregar a la colección existente.

ExcepciónCondición
ArgumentNullException

value es null.

En el ejemplo siguiente se muestra cómo usar la sobrecarga del método AddRange(CounterCreationDataCollection) para agregar objetos CounterCreationData de una colección CounterCreationDataCollection a otra colección CounterCreationDataCollection.

using System;
using System.Diagnostics;

public class CounterDataCollectionExample
{
    public static void Main()
    {
        try
        {

            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();
                // Add the 'CounterCreationDataCollection' to 'CounterCreationDataCollection' object.
                myNewCounterCollection.AddRange(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 + 1, myNewCounterCollection[i].CounterName);
            }
            else
            {
                Console.WriteLine("The category already exists");
            }

        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: {0}.", e.Message);
            return;
        }
    }
}


import System.*;
import System.Diagnostics.*;

public class CounterDataCollectionExample
{
    private static PerformanceCounter myCounter;

    public static void main(String[] args)
    {
        try {
            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();
                // Add the 'CounterCreationDataCollection' to 
                // 'CounterCreationDataCollection' object.
                myNewCounterCollection.AddRange(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 + 1),
                        myNewCounterCollection.get_Item(i).get_CounterName());
                }
            }
            else {
                Console.WriteLine("The category already exists");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: {0}.", e.get_Message());
            return;
        }
    } //main
} //CounterDataCollectionExample


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

Adiciones de comunidad

AGREGAR
Mostrar:
© 2016 Microsoft