次の方法で共有


PerformanceCounterCategory コンストラクタ ()

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

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

構文

'宣言
Public Sub New
'使用
Dim instance As New PerformanceCounterCategory
public PerformanceCounterCategory ()
public:
PerformanceCounterCategory ()
public PerformanceCounterCategory ()
public function PerformanceCounterCategory ()

解説

この PerformanceCounterCategory インスタンスをサーバー上のパフォーマンス オブジェクトに関連付ける前に、CategoryName プロパティを設定する必要があります。設定しないと、例外がスローされます。

使用例

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 クラス