PerformanceCounterCategory.CategoryName 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置定义此类别的性能对象的名称。
public:
property System::String ^ CategoryName { System::String ^ get(); void set(System::String ^ value); };
public string CategoryName { get; set; }
member this.CategoryName : string with get, set
Public Property CategoryName As String
属性值
性能计数器类别的名称或性能对象,此 PerformanceCounterCategory 实例将与之关联。
例外
CategoryName 是空字符串 ("")。
CategoryName 为 null
。
示例
下面的代码示例使用 PerformanceCounterCategory()创建 PerformanceCounterCategory 。 它会提示用户输入 PerformanceCounterCategory 和 计算机名称,然后根据输入的值设置 CategoryName 和 MachineName 属性。 然后,它显示 、 MachineName和 CategoryHelp 属性的值CategoryName,或者如果 PerformanceCounterCategory 无法访问 ,则显示错误消息。
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);
}
}
Sub Main(ByVal args() As String)
Dim categoryName As String = ""
Dim machineName As String = ""
Dim pcc As 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 Then
pcc.CategoryName = categoryName
End If
End While
While machineName.Length = 0
Console.Write( _
"Enter a non-blank computer name ['.' for local]: ")
machineName = Console.ReadLine().Trim
If machineName.Length > 0 Then
pcc.MachineName = machineName
End If
End While
' 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