PerformanceCounterCategory Constructor ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the PerformanceCounterCategory class, leaves the CategoryName property empty, and sets the MachineName property to the local computer.

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

public PerformanceCounterCategory()

The CategoryName property must be set before associating this PerformanceCounterCategory instance with a performance object on the server. Otherwise, an exception is thrown.

The following code example accepts a PerformanceCounterCategory name and a computer name from the command line. It creates a PerformanceCounterCategory using the constructor overload appropriate for the number of parameters provided, then displays its properties.

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);
    }
}

PerformanceCounterPermission

for reading performance counter categories. Associated enumeration: PerformanceCounterPermissionAccess.Read.

.NET Framework
Available since 1.1
Return to top
Show: