CounterCreationDataCollection.AddRange Method (CounterCreationDataCollection)


Adds the specified collection of CounterCreationData instances to the collection.

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

Public Sub AddRange (
	value As CounterCreationDataCollection


Type: System.Diagnostics.CounterCreationDataCollection

A collection of CounterCreationData instances to append to the existing collection.

Exception Condition

value is null.

The following example demonstrates how to use the AddRange(CounterCreationDataCollection) method overload to add CounterCreationData objects from one CounterCreationDataCollection to another CounterCreationDataCollection.

Imports System
Imports System.Diagnostics

Public Class CounterDataCollectionExample
   Private Shared myCounter As PerformanceCounter
   Public Shared Sub Main()

         Dim myCategoryName As String
         Dim numberOfCounters As Integer
         Console.Write("Enter the number of counters : ")
         numberOfCounters = Integer.Parse(Console.ReadLine())
         Dim myCounterCreationData(numberOfCounters-1) As CounterCreationData
         Dim i As Integer
         For i = 0 To numberOfCounters - 1
            Console.Write("Enter the counter name for {0} counter : ", i)
            myCounterCreationData(i) = New CounterCreationData()
            myCounterCreationData(i).CounterName = Console.ReadLine()
         Next i
         Dim myCounterCollection As New CounterCreationDataCollection(myCounterCreationData)
         Console.Write("Enter the category Name : ")
         myCategoryName = Console.ReadLine()
         ' Check if the category already exists or not.
         If Not PerformanceCounterCategory.Exists(myCategoryName) Then
            Dim myNewCounterCollection As New CounterCreationDataCollection()
            ' Add the 'CounterCreationDataCollection' to 'CounterCreationDataCollection' object.

                PerformanceCounterCategory.Create(myCategoryName, "Sample Category", _
                       PerformanceCounterCategoryType.SingleInstance, myNewCounterCollection)

            Console.WriteLine("The list of counters in CounterCollection are: ")

            For i = 0 To myNewCounterCollection.Count - 1
               Console.WriteLine("Counter {0} is '{1}'", i + 1, _
            Next i
            Console.WriteLine("The category already exists")
         End If

      Catch e As Exception
         Console.WriteLine("Exception: {0}.", e.Message)
      End Try
   End Sub 'Main
End Class 'CounterDataCollectionExample

.NET Framework
Available since 1.1
Return to top