Share via


PerformanceCounterCategory Constructeurs

Définition

Initialise une nouvelle instance de la classe PerformanceCounterCategory.

Surcharges

PerformanceCounterCategory()

Initialise une nouvelle instance de la classe PerformanceCounterCategory, laisse la propriété CategoryName vide et affecte l'ordinateur local comme valeur de la propriété MachineName.

PerformanceCounterCategory(String)

Initialise une nouvelle instance de la classe PerformanceCounterCategory, affecte à la propriété CategoryName la valeur spécifiée et affecte l'ordinateur local comme valeur de la propriété MachineName.

PerformanceCounterCategory(String, String)

Initialise une nouvelle instance de la classe PerformanceCounterCategory et affecte aux propriétés CategoryName et MachineName les valeurs spécifiées.

PerformanceCounterCategory()

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

Initialise une nouvelle instance de la classe PerformanceCounterCategory, laisse la propriété CategoryName vide et affecte l'ordinateur local comme valeur de la propriété MachineName.

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

Exemples

L’exemple de code suivant accepte un PerformanceCounterCategory nom et un nom d’ordinateur à partir de la ligne de commande. Il crée un PerformanceCounterCategory à l’aide de la surcharge de constructeur appropriée pour le nombre de paramètres fournis, puis affiche ses propriétés.

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

Remarques

La CategoryName propriété doit être définie avant d’associer cette PerformanceCounterCategory instance à un objet de performance sur le serveur. Sinon, une exception est levée.

Voir aussi

S’applique à

PerformanceCounterCategory(String)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

Initialise une nouvelle instance de la classe PerformanceCounterCategory, affecte à la propriété CategoryName la valeur spécifiée et affecte l'ordinateur local comme valeur de la propriété MachineName.

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

Paramètres

categoryName
String

Nom de la catégorie de compteurs de performance (objet de performance) à laquelle associer cette instance de PerformanceCounterCategory.

Exceptions

categoryName est une chaîne vide ("").

categoryName a la valeur null.

Exemples

L’exemple de code suivant accepte un PerformanceCounterCategory nom et un nom d’ordinateur à partir de la ligne de commande. Il crée un PerformanceCounterCategory à l’aide de la surcharge du constructeur qui est approprié pour le nombre de paramètres fournis, puis affiche ses propriétés.

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

Voir aussi

S’applique à

PerformanceCounterCategory(String, String)

Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs
Source:
PerformanceCounterCategory.cs

Initialise une nouvelle instance de la classe PerformanceCounterCategory et affecte aux propriétés CategoryName et MachineName les valeurs spécifiées.

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)

Paramètres

categoryName
String

Nom de la catégorie de compteurs de performance (objet de performance) à laquelle associer cette instance de PerformanceCounterCategory.

machineName
String

Ordinateur sur lequel résident la catégorie de compteurs de performance et les compteurs qui lui sont associés.

Exceptions

categoryName est une chaîne vide ("").

- ou -

La syntaxe machineName n'est pas valide.

categoryName a la valeur null.

Exemples

L’exemple de code suivant accepte un PerformanceCounterCategory nom et un nom d’ordinateur à partir de la ligne de commande. Il crée un PerformanceCounterCategory à l’aide de la surcharge du constructeur qui est approprié pour le nombre de paramètres fournis, puis affiche ses propriétés.

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

Voir aussi

S’applique à