次の方法で共有


PerformanceCounterCategory コンストラクタ (String)

PerformanceCounterCategory クラスの新しいインスタンスを初期化し、CategoryName プロパティを指定した値に設定し、MachineName プロパティをローカル コンピュータに設定します。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)

構文

'宣言
Public Sub New ( _
    categoryName As String _
)
'使用
Dim categoryName As String

Dim instance As New PerformanceCounterCategory(categoryName)
public PerformanceCounterCategory (
    string categoryName
)
public:
PerformanceCounterCategory (
    String^ categoryName
)
public PerformanceCounterCategory (
    String categoryName
)
public function PerformanceCounterCategory (
    categoryName : String
)

パラメータ

  • categoryName
    この PerformanceCounterCategory インスタンスを関連付けるパフォーマンス カウンタ カテゴリまたはパフォーマンス オブジェクトの名前。

例外

例外の種類 条件

ArgumentException

categoryName が空の文字列 ("") です。

ArgumentNullException

categoryName が null 参照 (Visual Basic では Nothing) です。

使用例

PerformanceCounterCategory 名およびコンピュータ名をコマンド ラインから受け取るコード例を次に示します。この例では、指定されたパラメータの数に適したコンストラクタ オーバーロードを使用して、PerformanceCounterCategory を作成し、プロパティを表示します。

Sub Main(ByVal args() As String)
    Dim categoryName As String = ""
    Dim machineName As String = ""
    Dim pcc As PerformanceCounterCategory

    ' Copy the supplied arguments into the local variables.
    Try
        categoryName = args(0)
        machineName = IIf(args(1) = ".", "", args(1))
    Catch ex As Exception
        ' Ignore the exception from non-supplied arguments.
    End Try

    ' Create a PerformanceCounterCategory object using 
    ' the appropriate constructor.
    If categoryName.Length = 0 Then
        pcc = New PerformanceCounterCategory
    ElseIf machineName.Length = 0 Then
        pcc = New PerformanceCounterCategory(categoryName)
    Else
        pcc = New PerformanceCounterCategory(categoryName, machineName)
    End If

    ' Display the properties of the PerformanceCounterCategory object.
    Try
        Console.WriteLine("  Category:  {0}", pcc.CategoryName)
        Console.WriteLine("  Computer:  {0}", pcc.MachineName)
        Console.WriteLine("  Help text: {0}", pcc.CategoryHelp)
    Catch ex As Exception
        Console.WriteLine("Error getting the properties of the " & _
            "PerformanceCounterCategory object:")
        Console.WriteLine(ex.Message)
    End Try
End Sub
public static void Main(string[] args)
{
    string categoryName = "";
    string machineName = "";
    PerformanceCounterCategory pcc;

    // Copy the supplied arguments into the local variables.
    try
    {
        categoryName = args[0];
        machineName = args[1]=="."? "": args[1];
    }
    catch(Exception ex)
    {
        // Ignore the exception from non-supplied arguments.
    }

    // Create a PerformanceCounterCategory object using 
    // the appropriate constructor.
    if (categoryName.Length==0)
    {
        pcc = new PerformanceCounterCategory();
    }
    else if(machineName.Length==0)
    {
        pcc = new PerformanceCounterCategory(categoryName);
    }
    else
    {
        pcc = new PerformanceCounterCategory(categoryName, machineName);
    }

    // Display the properties of the PerformanceCounterCategory object.
    try
    {
        Console.WriteLine("  Category:  {0}", pcc.CategoryName);
        Console.WriteLine("  Computer:  {0}", pcc.MachineName);
        Console.WriteLine("  Help text: {0}", pcc.CategoryHelp);
    }
    catch(Exception ex)
    {
        Console.WriteLine("Error getting the properties of the " +
            "PerformanceCounterCategory object:");
        Console.WriteLine(ex.Message);
    }
}

.NET Framework のセキュリティ

プラットフォーム

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

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

PerformanceCounterCategory クラス
PerformanceCounterCategory メンバ
System.Diagnostics 名前空間
CategoryName
MachineName
PerformanceCounter クラス