This class represents a Windows NT, 2000, or XP performance counter that can be accessed using the Performance Administrative Tool. PerformanceCounter s already exist for system devices, such as processor, disk, or memory usage, as well as for system resources, such as processes or threads. Using the PerformanceCounter class, you can both read from and write performance data to existing custom counters. To create your own custom performance counters, use PerformanceCounterCategory.Create( ) . You can write to a performance counter by using one of the PerformanceCounter constructors that takes the boolean readonly argument. Set that argument to false to create a performance counter that you can write to. To set the value of a performance counter, call IncrementBy( ) , Increment( ) , or Decrement( ) , or set the RawValue to the desired value. To access an existing performance counter, create an instance of PerformanceCounter with the CategoryName and CounterName set to that of an available category and an existing performance counter. The category and counter names are case-insensitive, so you could sample the available memory by calling the constructor as PerformanceCounter("memory ", " available mbytes") . Consult the Performance Administrative Tool for the available performance counters. You can explicitly set the CategoryName and CounterName (and the optional InstanceName and MachineName ) properties, if you choose not to set these using the constructor. To obtain a new data sample for a counter, call either NextValue( ) or NextSample( ) . NextSample( ) returns a CounterSample structure that represents the raw captured performance data. NextValue( ) fetches the next sample and calculates its value based on the raw data it contains. To permanently remove a counter, call RemoveInstance( ) . If you attempt to modify or remove a counter in which the ReadOnly property is set to true , an InvalidOperationException is returned. public sealed class PerformanceCounter : System.ComponentModel.Component, System.ComponentModel.ISupportInitialize { // Public Constructors public PerformanceCounter ( ); public PerformanceCounter (string categoryName , string counterName ); public PerformanceCounter (string categoryName , string counterName , bool readOnly ); public PerformanceCounter (string categoryName , string counterName , string instanceName ); public PerformanceCounter (string categoryName , string counterName , string instanceName , bool readOnly ); public PerformanceCounter (string categoryName , string counterName , string instanceName , string machineName ); // Public Static Fields public static int DefaultFileMappingSize ; // =524288 // Public Instance Properties public string CategoryName {set; get; } public string CounterHelp {get; } public string CounterName {set; get; } public PerformanceCounterType CounterType {get; } public string InstanceName {set; get; } public string MachineName {set; get; } public long RawValue {set; get; } public bool ReadOnly {set; get; } // Public Static Methods public static void CloseSharedResources ( ); // Public Instance Methods public void BeginInit ( ); // implements System.ComponentModel.ISupportInitialize public void Close ( ); public long Decrement ( ); public void EndInit ( ); // implements System.ComponentModel.ISupportInitialize public long Increment ( ); public long IncrementBy (long value ); public CounterSample NextSample ( ); public float NextValue ( ); public void RemoveInstance ( ); // Protected Instance Methods protected override void Dispose (bool disposing ); // overrides System.ComponentModel.Component } HierarchySystem.Object System.MarshalByRefObject System.ComponentModel.Component(System.ComponentModel.IComponent, System.IDisposable) PerformanceCounter(System.ComponentModel.ISupportInitialize) Returned ByPerformanceCounterCategory.GetCounters( ) |