PerformanceCounterCategory.CategoryName 屬性

定義

取得或設定定義這個分類的效能物件名稱。

C#
public string CategoryName { get; set; }

屬性值

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

例外狀況

CategoryName 為空字串 ("")。

範例

下列程式代碼範例會 PerformanceCounterCategory 使用 PerformanceCounterCategory()建立 。 它會提示使用者輸入 PerformanceCounterCategory 和 計算機名稱,然後從輸入的值設定 CategoryNameMachineName 屬性。 然後,它會顯示、 和屬性的值CategoryName,如果無法存取,則會顯示錯誤訊息PerformanceCounterCategoryCategoryHelpMachineName

C#
public static void Main(string[] args)
{
    string categoryName = "";
    string machineName = "";
    PerformanceCounterCategory pcc = new PerformanceCounterCategory();

    // Prompt for fields and set the corresponding properties.
    while (categoryName.Length==0)
    {
        Console.Write("Please enter a non-blank category name: ");
        categoryName = Console.ReadLine().Trim();
        if (categoryName.Length>0)
        {
            pcc.CategoryName = categoryName;
        }
    }
    while (machineName.Length==0)
    {
        Console.Write("Enter a non-blank computer name ['.' for local]: ");
        machineName = Console.ReadLine().Trim();
        if (machineName.Length>0)
        {
            pcc.MachineName = 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 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

另請參閱