This documentation is archived and is not being maintained.

PerformanceCounter.InstanceName Property

Gets or sets an instance name for this performance counter.

[Visual Basic]
Public Property InstanceName As String
[C#]
public string InstanceName {get; set;}
[C++]
public: __property String* get_InstanceName();
public: __property void set_InstanceName(String*);
[JScript]
public function get InstanceName() : String;
public function set InstanceName(String);

Property Value

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

Remarks

In some situations, categories are subdivided into instances, which track data about multiple occurrences of the object that a category relates to. Instances apply to the category as whole, rather than to individual counters. Every counter within a category has each instance defined for the category. For example, the Process category contains instances named Idle and System. Every counter within the Process category thus contains data for each instance, showing information about either idle processes or system processes.

Many categories do not contain multiple instances, so you can leave this property empty to indicate that no instance is associated with the category.

If this PerformanceCounter instance points to a noncustom category, you can choose from only the existing category instances. You can create new category instances only in custom categories, which allow you to define as many counters and category instances as you need.

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.

Example

[Visual Basic] 
Dim PC As New PerformanceCounter()
PC.CategoryName = "Process"
PC.CounterName = "Private Bytes"
PC.InstanceName = "Explorer"
MessageBox.Show(PC.NextValue().ToString())

[C#] 
PerformanceCounter PC=new PerformanceCounter();
PC.CategoryName="Process";
PC.CounterName="Private Bytes";
PC.InstanceName="Explorer";
MessageBox.Show(PC.NextValue().ToString());

[C++] 
PerformanceCounter* PC = new PerformanceCounter();
PC->CategoryName=S"Process";
PC->CounterName=S"Private Bytes";
PC->InstanceName=S"Explorer";
MessageBox::Show(PC->NextValue().ToString());

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

PerformanceCounter Class | PerformanceCounter Members | System.Diagnostics Namespace

Show: