Modifica

Condividi tramite


PerformanceCounter.InstanceName Property

Definition

Gets or sets an instance name for this performance counter.

public:
 property System::String ^ InstanceName { System::String ^ get(); void set(System::String ^ value); };
public string InstanceName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string InstanceName { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string InstanceName { get; set; }
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string InstanceName { get; set; }
member this.InstanceName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.InstanceName : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.InstanceName : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.InstanceNameConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.InstanceName : string with get, set
Public Property InstanceName As String

Property Value

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

Attributes

Examples

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() );
PerformanceCounter performanceCounter = new PerformanceCounter();
performanceCounter.CategoryName = "Process";
performanceCounter.CounterName = "Private Bytes";
performanceCounter.InstanceName = "Explorer";
MessageBox.Show(performanceCounter.NextValue().ToString());
Dim PC As New PerformanceCounter()
PC.CategoryName = "Process"
PC.CounterName = "Private Bytes"
PC.InstanceName = "Explorer"
MessageBox.Show(PC.NextValue().ToString())

Remarks

Note

Instance names must be shorter than 128 characters in length.

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.

Note

Do not use the characters "(", ")", "#", "\", or "/" in the instance name. If any of these characters are used, the Performance Console (see Runtime Profiling) may not correctly display the instance values.

If the instance name is automatically generated and might contain the characters "(", ")", "#", "\", or "/", use the character mapping in the following table.

Character Mapped character
( [
) ]
# _
\ _
/ _

The FriendlyName property of the AppDomain object obtained from the AppDomain.CurrentDomain property is a common source of instance names that can contain invalid characters.

Applies to