PerformanceCounterCategory 建構函式

定義

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

多載

PerformanceCounterCategory()

初始化 PerformanceCounterCategory 類別的新執行個體,將 CategoryName 屬性保留為空的,並將 MachineName 屬性設定為本機電腦。

PerformanceCounterCategory(String)

初始化 PerformanceCounterCategory 類別的新執行個體,將 CategoryName 屬性設定為指定值,並將 MachineName 屬性設定為本機電腦。

PerformanceCounterCategory(String, String)

初始化 PerformanceCounterCategory 類別的新執行個體,並將 CategoryNameMachineName 屬性設定為指定值。

PerformanceCounterCategory()

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

初始化 PerformanceCounterCategory 類別的新執行個體,將 CategoryName 屬性保留為空的,並將 MachineName 屬性設定為本機電腦。

C#
public PerformanceCounterCategory ();

範例

下列程式代碼範例會接受 PerformanceCounterCategory 命令行中的名稱和計算機名稱。 它會使用適用於所提供參數數目的建構函式多載來建立 PerformanceCounterCategory ,然後顯示其屬性。

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

備註

CategoryName 將這個 PerformanceCounterCategory 實例與伺服器上的性能物件建立關聯之前,必須先設定 屬性。 否則,會擲回例外狀況。

另請參閱

適用於

.NET Framework 4.8.1 和其他版本
產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

PerformanceCounterCategory(String)

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

初始化 PerformanceCounterCategory 類別的新執行個體,將 CategoryName 屬性設定為指定值,並將 MachineName 屬性設定為本機電腦。

C#
public PerformanceCounterCategory (string categoryName);

參數

categoryName
String

效能計數器分類或效能物件的名稱,用來與這個 PerformanceCounterCategory 執行個體相關聯。

例外狀況

categoryName 為空字串 ("")。

categoryNamenull

範例

下列程式代碼範例會接受 PerformanceCounterCategory 命令行中的名稱和計算機名稱。 它會使用適用於所提供參數數目的建構函式多載來建立 PerformanceCounterCategory ,然後顯示其屬性。

C#
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 4.8.1 和其他版本
產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

PerformanceCounterCategory(String, String)

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

初始化 PerformanceCounterCategory 類別的新執行個體,並將 CategoryNameMachineName 屬性設定為指定值。

C#
public PerformanceCounterCategory (string categoryName, string machineName);

參數

categoryName
String

效能計數器分類或效能物件的名稱,用來與這個 PerformanceCounterCategory 執行個體相關聯。

machineName
String

效能計數器分類和其相關計數器所在的電腦。

例外狀況

categoryName 為空字串 ("")。

-或-

machineName 語法無效。

categoryNamenull

範例

下列程式代碼範例會接受 PerformanceCounterCategory 命令行中的名稱和計算機名稱。 它會使用適用於所提供參數數目的建構函式多載來建立 PerformanceCounterCategory ,然後顯示其屬性。

C#
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 4.8.1 和其他版本
產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9