CounterCreationData.CounterName 屬性

定義

取得或設定自訂計數器的名稱。

public:
 property System::String ^ CounterName { System::String ^ get(); void set(System::String ^ value); };
public string CounterName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string CounterName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string CounterName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string CounterName { get; set; }
member this.CounterName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.CounterName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.CounterName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.CounterName : string with get, set
Public Property CounterName As String

屬性值

計數器的名稱,它是它所在分類中唯一的名稱。

屬性

例外狀況

指定值是 null

指定值的長度不在 1 到 80 個字元之間,或指定值包含雙引號、控制字元或前後空格。

範例

下列程式代碼範例示範如何取得和設定 CounterName 屬性。 此範例會建立兩個計數器,並使用不同的技術來設定其 CounterName 屬性。 初始化第一個計數器時, CounterName 數據會傳遞至建構函式,而第二個計數器則會明確設定 屬性。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

int main()
{
   CounterCreationDataCollection^ myCol = gcnew CounterCreationDataCollection;
   
   // Create two custom counter objects.
   CounterCreationData^ myCounter1 = gcnew CounterCreationData( "Counter1","First custom counter",PerformanceCounterType::CounterDelta32 );
   CounterCreationData^ myCounter2 = gcnew CounterCreationData;
   
   // Set the properties of the 'CounterCreationData' Object*.
   myCounter2->CounterName = "Counter2";
   myCounter2->CounterHelp = "Second custom counter";
   myCounter2->CounterType = PerformanceCounterType::NumberOfItemsHEX32;
   
   // Add custom counter objects to CounterCreationDataCollection.
   myCol->Add( myCounter1 );
   myCol->Add( myCounter2 );
   if ( PerformanceCounterCategory::Exists( "New Counter Category" ) )
      PerformanceCounterCategory::Delete( "New Counter Category" );
   
   // Bind the counters to a PerformanceCounterCategory.
   PerformanceCounterCategory^ myCategory = PerformanceCounterCategory::Create( "New Counter Category", "Category Help", myCol );
   Console::WriteLine( "Counter Information:" );
   Console::WriteLine( "Category Name: {0}", myCategory->CategoryName );
   for ( int i = 0; i < myCol->Count; i++ )
   {
      // Display the properties of the CounterCreationData objects.
      Console::WriteLine( "CounterName : {0}", myCol[ i ]->CounterName );
      Console::WriteLine( "CounterHelp : {0}", myCol[ i ]->CounterHelp );
      Console::WriteLine( "CounterType : {0}", myCol[ i ]->CounterType );
   }
}
using System;
using System.Diagnostics;

namespace MyDiagnostics
{
    class MyCounterCreationData
    {
        static void Main()
        {
            CounterCreationDataCollection myCol =
                                       new CounterCreationDataCollection();

            // Create two custom counter objects.
            CounterCreationData myCounter1 = new CounterCreationData("Counter1",
               "First custom counter", PerformanceCounterType.CounterDelta32);

            CounterCreationData myCounter2 = new CounterCreationData();

            // Set the properties of the 'CounterCreationData' object.
            myCounter2.CounterName = "Counter2";
            myCounter2.CounterHelp = "Second custom counter";
            myCounter2.CounterType = PerformanceCounterType.NumberOfItemsHEX32;

            // Add custom counter objects to CounterCreationDataCollection.
            myCol.Add(myCounter1);
            myCol.Add(myCounter2);

            if (PerformanceCounterCategory.Exists("New Counter Category"))
                PerformanceCounterCategory.Delete("New Counter Category");

            // Bind the counters to a PerformanceCounterCategory.
            PerformanceCounterCategory myCategory =
                  PerformanceCounterCategory.Create("New Counter Category", "Category Help",
                PerformanceCounterCategoryType.SingleInstance, myCol);

            Console.WriteLine("Counter Information:");
            Console.WriteLine("Category Name: " + myCategory.CategoryName);
            for (int i = 0; i < myCol.Count; i++)
            {
                // Display the properties of the CounterCreationData objects.
                Console.WriteLine("CounterName : " + myCol[i].CounterName);
                Console.WriteLine("CounterHelp : " + myCol[i].CounterHelp);
                Console.WriteLine("CounterType : " + myCol[i].CounterType);
            }
        }
    }
}
Imports System.Diagnostics

Namespace MyDiagnostics

    Class MyCounterCreationData

        Shared Sub Main()
            Dim myCol As New CounterCreationDataCollection()

            ' Create two custom counter objects.
            Dim myCounter1 As New CounterCreationData("Counter1", "First custom counter", _
                                      PerformanceCounterType.CounterDelta32)
            Dim myCounter2 As New CounterCreationData()

            ' Set the properties of the 'CounterCreationData' object.
            myCounter2.CounterName = "Counter2"
            myCounter2.CounterHelp = "Second custom counter"
            myCounter2.CounterType = PerformanceCounterType.NumberOfItemsHEX32

            ' Add custom counter objects to CounterCreationDataCollection.
            myCol.Add(myCounter1)
            myCol.Add(myCounter2)

            If PerformanceCounterCategory.Exists("New Counter Category") Then
                PerformanceCounterCategory.Delete("New Counter Category")
            End If
            ' Bind the counters to a PerformanceCounterCategory.
            Dim myCategory As PerformanceCounterCategory = PerformanceCounterCategory.Create("New " + _
                   "Counter Category", "Category Help", _
                   PerformanceCounterCategoryType.SingleInstance, myCol)

            Console.WriteLine("Counter Information:")
            Console.WriteLine("Category Name: " + myCategory.CategoryName)
            Dim i As Integer
            For i = 0 To myCol.Count - 1
                ' Display the properties of the CounterCreationData objects.
                Console.WriteLine("CounterName : " + myCol(i).CounterName)
                Console.WriteLine("CounterHelp : " + myCol(i).CounterHelp)
                Console.WriteLine("CounterType : " + myCol(i).CounterType.ToString())
            Next i
        End Sub
    End Class
End Namespace 'MyDiagnostics

適用於

另請參閱