PerformanceCounter Constructor

Initializes a new, read-only instance of the PerformanceCounter class, without associating the instance with any system or custom performance counter.

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



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

This overload of the constructor sets the CategoryName, CounterName, and InstanceName properties to empty strings (""), and sets the MachineName property to the local computer, (".").

This constructor does not initialize the performance counter, so it does not associate the instance with an existing counter on the local computer. To point to a specific performance counter, set the CategoryName, CounterName, and, optionally, the InstanceName and MachineName properties before reading any other properties or attempting to read from a counter. To write to a performance counter, set the ReadOnly property to false.


The HostProtectionAttribute attribute applied to this member has the following Resources property value: Synchronization | SharedState. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example creates a default instance of the PerformanceCounter class. After the instance is created, the CategoryName, CounterName, and InstanceName property values are set, and the results of a call to the NextValue method are displayed.

PerformanceCounter^ PC = gcnew PerformanceCounter;
PC->CategoryName = "Process";
PC->CounterName = "Private Bytes";
PC->InstanceName = "Explorer";
MessageBox::Show( PC->NextValue().ToString() );

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft