共用方式為


PerformanceCounterCategory 建構函式

定義

初始化 PerformanceCounterCategory 類別的新執行個體。

多載

名稱 Description
PerformanceCounterCategory()

初始化該類別的新實例 PerformanceCounterCategory ,將該屬性留 CategoryName 空,並將該屬性設 MachineName 為本地電腦。

PerformanceCounterCategory(String)

初始化該類別的新實例 PerformanceCounterCategory ,將屬性設 CategoryName 為指定的值,並將屬性設定 MachineName 為本地電腦。

PerformanceCounterCategory(String, String)

初始化該類別的新實例PerformanceCounterCategory,並將 和 MachineName 屬性設CategoryName為指定的值。

PerformanceCounterCategory()

來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs

初始化該類別的新實例 PerformanceCounterCategory ,將該屬性留 CategoryName 空,並將該屬性設 MachineName 為本地電腦。

public:
 PerformanceCounterCategory();
public PerformanceCounterCategory();
Public Sub New ()

範例

以下程式碼範例接受 PerformanceCounterCategory 命令列的名稱與電腦名稱。 它會根據所提供的參數數量,建立 PerformanceCounterCategory 一個建構子過載,然後顯示其屬性。

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);
    }
}
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

備註

必須先設定該 CategoryName 屬性,才能將此 PerformanceCounterCategory 實例與伺服器上的效能物件關聯。 否則會拋出例外狀況。

另請參閱

適用於

PerformanceCounterCategory(String)

來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs

初始化該類別的新實例 PerformanceCounterCategory ,將屬性設 CategoryName 為指定的值,並將屬性設定 MachineName 為本地電腦。

public:
 PerformanceCounterCategory(System::String ^ categoryName);
public PerformanceCounterCategory(string categoryName);
new System.Diagnostics.PerformanceCounterCategory : string -> System.Diagnostics.PerformanceCounterCategory
Public Sub New (categoryName As String)

參數

categoryName
String

用來關聯此 PerformanceCounterCategory 實例的效能計數器類別或效能物件名稱。

例外狀況

這是一個 categoryName 空字串(“”)。

categoryNamenull

範例

以下程式碼範例接受 PerformanceCounterCategory 命令列的名稱與電腦名稱。 它會根據所提供參數數量,使用適當的建構子過載來建立 PerformanceCounterCategory 一個,然後顯示其屬性。

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);
    }
}
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

另請參閱

適用於

PerformanceCounterCategory(String, String)

來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs
來源:
PerformanceCounterCategory.cs

初始化該類別的新實例PerformanceCounterCategory,並將 和 MachineName 屬性設CategoryName為指定的值。

public:
 PerformanceCounterCategory(System::String ^ categoryName, System::String ^ machineName);
public PerformanceCounterCategory(string categoryName, string machineName);
new System.Diagnostics.PerformanceCounterCategory : string * string -> System.Diagnostics.PerformanceCounterCategory
Public Sub New (categoryName As String, machineName As String)

參數

categoryName
String

用來關聯此 PerformanceCounterCategory 實例的效能計數器類別或效能物件名稱。

machineName
String

存在效能計數器類別及其相關計數器的電腦。

例外狀況

這是一個 categoryName 空字串(“”)。

-或-

machineName 法無效。

categoryNamenull

範例

以下程式碼範例接受 PerformanceCounterCategory 命令列的名稱與電腦名稱。 它會根據所提供參數數量,使用適當的建構子過載來建立 PerformanceCounterCategory 一個,然後顯示其屬性。

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);
    }
}
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

另請參閱

適用於