This topic has not yet been rated - Rate this topic

PerformanceCounterCategory Constructor (String, String)

Initializes a new instance of the PerformanceCounterCategory class and sets the CategoryName and MachineName properties to the specified values.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)
public PerformanceCounterCategory(
	string categoryName,
	string machineName


Type: System.String

The name of the performance counter category, or performance object, with which to associate this PerformanceCounterCategory instance.

Type: System.String

The computer on which the performance counter category and its associated counters exist.


The categoryName is an empty string ("").


The machineName syntax is invalid.


The categoryName is null.

The following code example accepts a PerformanceCounterCategory name and a computer name from the command line. It creates a PerformanceCounterCategory using the constructor overload that is 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. 
        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);
        pcc = new PerformanceCounterCategory(categoryName, machineName);

    // Display the properties of the PerformanceCounterCategory object. 
        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:");

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.