PerformanceCounterCategory 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 PerformanceCounterCategory 類別的新執行個體。
多載
PerformanceCounterCategory() |
初始化 PerformanceCounterCategory 類別的新執行個體,將 CategoryName 屬性保留為空的,並將 MachineName 屬性設定為本機電腦。 |
PerformanceCounterCategory(String) |
初始化 PerformanceCounterCategory 類別的新執行個體,將 CategoryName 屬性設定為指定值,並將 MachineName 屬性設定為本機電腦。 |
PerformanceCounterCategory(String, String) |
初始化 PerformanceCounterCategory 類別的新執行個體,並將 CategoryName 和 MachineName 屬性設定為指定值。 |
PerformanceCounterCategory()
初始化 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 類別的新執行個體,將 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
為空字串 ("")。
categoryName
為 null
。
範例
下列程式代碼範例會接受 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 類別的新執行個體,並將 CategoryName 和 MachineName 屬性設定為指定值。
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
為 null
。
範例
下列程式代碼範例會接受 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