PerformanceCounter Constructor (String, String, String, Boolean)

PerformanceCounter Constructor (String, String, String, Boolean)

Initializes a new, read-only or read/write instance of the PerformanceCounter class and associates it with the specified system or custom performance counter and category instance on the local computer.

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

public PerformanceCounter (
	string categoryName,
	string counterName,
	string instanceName,
	bool readOnly
)
public PerformanceCounter (
	String categoryName, 
	String counterName, 
	String instanceName, 
	boolean readOnly
)
public function PerformanceCounter (
	categoryName : String, 
	counterName : String, 
	instanceName : String, 
	readOnly : boolean
)

Parameters

categoryName

The name of the performance counter category (performance object) with which this performance counter is associated.

counterName

The name of the performance counter.

instanceName

The name of the performance counter category instance, or an empty string (""), if the category contains a single instance.

readOnly

true to access a counter in read-only mode; false to access a counter in read/write mode.

Exception typeCondition

InvalidOperationException

The categoryName is an empty string ("").

-or-

The counterName is an empty string ("").

-or-

The read/write permission setting requested is invalid for this counter.

-or-

The category specified does not exist. (If readOnly is true.)

-or-

The category specified is not a .NET Framework custom category. (If readOnly is false.)

-or-

The category specified is marked as multi-instance and requires the performance counter to be created with an instance name.

-or-

The instanceName is longer than 127 characters.

ArgumentNullException

The categoryName or counterName parameter is a null reference (Nothing in Visual Basic).

Win32Exception

An error occurred when accessing a system API.

PlatformNotSupportedException

The platform is Windows 98 or Windows Millennium Edition (Me), which does not support performance counters.

The parameter strings are not case sensitive.

Use this overload to access a performance counter in either read-only or read/write mode.

This overload of the constructor sets the CategoryName, CounterName, and InstanceName properties to the values you pass in, it and sets the MachineName property to the local computer, ".".

This constructor initializes the performance counter and associates the instance with an existing counter (either a system or a custom counter) on the local computer. The values that you pass in for the CategoryName, CounterName, and InstanceName properties must point to an existing performance counter on the local computer. If either the performance counter instance that you point to is not valid, calling the constructor throws an exception.

NoteNote

You can use this overload to connect to a system counter, but you cannot write to a system counter. Therefore, setting readOnly to false when connecting to a system counter causes the constructor to throw an exception.

To create a performance category instance, specify an instanceName on the PerformanceCounter constructor. If the category instance specified by instanceName already exists the new object will reference the existing category instance.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2016 Microsoft