CounterCreationDataCollection Constructor (array<CounterCreationData^>^)
.NET Framework (current version)
Initializes a new instance of the CounterCreationDataCollection class by using the specified array of CounterCreationData instances.
Assembly: System (in System.dll)
Parameters
- value
-
Type:
array<System.Diagnostics::CounterCreationData^>^
An array of CounterCreationData instances with which to initialize this CounterCreationDataCollection.
| Exception | Condition |
|---|---|
| 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 = Int32::Parse( Console::ReadLine() ); array<CounterCreationData^>^myCounterCreationData = gcnew array<CounterCreationData^>(numberOfCounters); for ( int i = 0; i < numberOfCounters; i++ ) { Console::Write( "Enter the counter name for {0} counter : ", i ); myCounterCreationData[ i ] = gcnew CounterCreationData; myCounterCreationData[ i ]->CounterName = Console::ReadLine(); } CounterCreationDataCollection^ myCounterCollection = gcnew CounterCreationDataCollection( myCounterCreationData ); // Create the category. PerformanceCounterCategory::Create( myCategoryName, "Sample Category", myCounterCollection ); for ( int i = 0; i < numberOfCounters; i++ ) { myCounter = gcnew PerformanceCounter( myCategoryName,myCounterCreationData[ i ]->CounterName,"",false ); } 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
Available since 1.1
Available since 1.1
Show: