PerformanceCounterCategory Costruttori

Definizione

Inizializza una nuova istanza della classe PerformanceCounterCategory.

Overload

PerformanceCounterCategory()

Consente di inizializzare una nuova istanza della classe PerformanceCounterCategory, lascia vuota la proprietà CategoryName e imposta la proprietà MachineName sul computer locale.

PerformanceCounterCategory(String)

Consente di inizializzare una nuova istanza della classe PerformanceCounterCategory, imposta la proprietà CategoryName sul valore specificato e la proprietà MachineName sul computer locale.

PerformanceCounterCategory(String, String)

Consente di inizializzare una nuova istanza della classe PerformanceCounterCategory e imposta le proprietà CategoryName e MachineName sui valori specificati.

PerformanceCounterCategory()

Origine:
PerformanceCounterCategory.cs
Origine:
PerformanceCounterCategory.cs
Origine:
PerformanceCounterCategory.cs

Consente di inizializzare una nuova istanza della classe PerformanceCounterCategory, lascia vuota la proprietà CategoryName e imposta la proprietà MachineName sul computer locale.

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

Esempio

Nell'esempio di codice seguente viene accettato un nome e un PerformanceCounterCategory nome computer dalla riga di comando. Crea un PerformanceCounterCategory oggetto usando l'overload del costruttore appropriato per il numero di parametri forniti, quindi visualizza le relative proprietà.

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

Commenti

La CategoryName proprietà deve essere impostata prima di associare questa PerformanceCounterCategory istanza a un oggetto prestazioni nel server. In caso contrario, viene generata un'eccezione.

Vedi anche

Si applica a

PerformanceCounterCategory(String)

Origine:
PerformanceCounterCategory.cs
Origine:
PerformanceCounterCategory.cs
Origine:
PerformanceCounterCategory.cs

Consente di inizializzare una nuova istanza della classe PerformanceCounterCategory, imposta la proprietà CategoryName sul valore specificato e la proprietà MachineName sul computer locale.

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

Parametri

categoryName
String

Il nome della categoria del contatore delle prestazioni o oggetto delle prestazioni al quale associare questa istanza di PerformanceCounterCategory.

Eccezioni

categoryName è una stringa vuota ("").

L'elemento categoryName è null.

Esempio

Nell'esempio di codice seguente viene accettato un nome e un PerformanceCounterCategory nome computer dalla riga di comando. Crea un PerformanceCounterCategory oggetto usando l'overload del costruttore appropriato per il numero di parametri forniti, quindi visualizza le relative proprietà.

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

Vedi anche

Si applica a

PerformanceCounterCategory(String, String)

Origine:
PerformanceCounterCategory.cs
Origine:
PerformanceCounterCategory.cs
Origine:
PerformanceCounterCategory.cs

Consente di inizializzare una nuova istanza della classe PerformanceCounterCategory e imposta le proprietà CategoryName e MachineName sui valori specificati.

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)

Parametri

categoryName
String

Il nome della categoria del contatore delle prestazioni o oggetto delle prestazioni al quale associare questa istanza di PerformanceCounterCategory.

machineName
String

Il computer sul quale sono presenti la categoria del contatore delle prestazioni e i contatori associati.

Eccezioni

categoryName è una stringa vuota ("").

-oppure-

La sintassi della proprietà machineName non è valida.

L'elemento categoryName è null.

Esempio

Nell'esempio di codice seguente viene accettato un nome e un PerformanceCounterCategory nome computer dalla riga di comando. Crea un PerformanceCounterCategory oggetto usando l'overload del costruttore appropriato per il numero di parametri forniti, quindi visualizza le relative proprietà.

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

Vedi anche

Si applica a