InstanceDataCollection.Item[String] Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan data instans yang terkait dengan penghitung ini. Ini biasanya sekumpulan nilai penghitung mentah.
public:
property System::Diagnostics::InstanceData ^ default[System::String ^] { System::Diagnostics::InstanceData ^ get(System::String ^ instanceName); };
public System.Diagnostics.InstanceData this[string instanceName] { get; }
member this.Item(string) : System.Diagnostics.InstanceData
Default Public ReadOnly Property Item(instanceName As String) As InstanceData
Parameter
- instanceName
- String
Nama instans kategori penghitung kinerja, atau string kosong ("") jika kategori berisi satu instans.
Nilai Properti
Item InstanceData , tempat objek diindeks InstanceDataCollection .
Pengecualian
Parameternya instanceName
adalah null
.
Contoh
Contoh kode berikut menerima PerformanceCounter nama kategori, nama penghitung, dan nama instans dari baris perintah. Ini mendapatkan InstanceDataCollectionCollection untuk kategori , yang merupakan kumpulan InstanceDataCollection objek. Dari situ akan mendapatkan yang khusus InstanceDataCollection untuk penghitung yang ditentukan. Kemudian, jika instans ada, contoh menggunakan Item[] properti (dirujuk sebagai pengindeks) untuk mendapatkan objek terkait InstanceData .
public static void Main(string[] args)
{
// These values can be used as arguments.
string categoryName = "Process";
string counterName = "Private Bytes";
string instanceName = "Explorer";
InstanceDataCollection idCol;
const string SINGLE_INSTANCE_NAME = "systemdiagnosticsperfcounterlibsingleinstance";
// Copy the supplied arguments into the local variables.
try
{
categoryName = args[0];
counterName = args[1];
instanceName = args[2];
}
catch
{
// Ignore the exception from non-supplied arguments.
}
try
{
// Get the InstanceDataCollectionCollection for this category.
PerformanceCounterCategory pcc = new PerformanceCounterCategory(categoryName);
InstanceDataCollectionCollection idColCol = pcc.ReadCategory();
// Get the InstanceDataCollection for this counter.
idCol = idColCol[counterName];
if (idCol==null)
{
throw new Exception("Counter does not exist.");
}
}
catch(Exception ex)
{
Console.WriteLine("An error occurred getting the InstanceDataCollection for " +
"category \"{0}\", counter \"{1}\"." + "\n" + ex.Message, categoryName, counterName);
return;
}
// If the instance name is empty, use the single-instance name.
if (instanceName.Length==0)
{
instanceName = SINGLE_INSTANCE_NAME;
}
// Check if this instance name exists using the Contains
// method of the InstanceDataCollection.
if (!idCol.Contains(instanceName))
{
Console.WriteLine("Instance \"{0}\" does not exist in counter \"{1}\", " +
"category \"{2}\".", instanceName, counterName, categoryName);
return;
}
else
{
// The instance name exists, now get its InstanceData object
// using the indexer (Item property) for the InstanceDataCollection.
InstanceData instData = idCol[instanceName];
Console.WriteLine("CategoryName: {0}", categoryName);
Console.WriteLine("CounterName: {0}", counterName);
Console.WriteLine("InstanceName: {0}", instData.InstanceName);
Console.WriteLine("RawValue: {0}", instData.RawValue);
}
}
Sub Main(ByVal args() As String)
' These values can be used as arguments.
Dim categoryName As String = "Process"
Dim counterName As String = "Private Bytes"
Dim instanceName As String = "Explorer"
Dim idCol As InstanceDataCollection
Const SINGLE_INSTANCE_NAME As String = _
"systemdiagnosticsperfcounterlibsingleinstance"
' Copy the supplied arguments into the local variables.
Try
categoryName = args(0)
counterName = args(1)
instanceName = args(2)
Catch ex As Exception
' Ignore the exception from non-supplied arguments.
End Try
Try
' Get the InstanceDataCollectionCollection for this category.
Dim pcc As New PerformanceCounterCategory(categoryName)
Dim idColCol As InstanceDataCollectionCollection = _
pcc.ReadCategory()
' Get the InstanceDataCollection for this counter.
idCol = idColCol(counterName)
If idCol Is Nothing Then
Throw New Exception("Counter does not exist.")
End If
Catch ex As Exception
Console.WriteLine( _
"An error occurred getting the InstanceDataCollection for " & _
"category ""{0}"", counter ""{1}""." & vbCrLf & ex.Message, _
categoryName, counterName)
Return
End Try
' If the instance name is empty, use the single-instance name.
If instanceName.Length = 0 Then
instanceName = SINGLE_INSTANCE_NAME
End If
' Check if this instance name exists using the Contains
' method of the InstanceDataCollection.
If Not idCol.Contains(instanceName) Then
Console.WriteLine( _
"Instance ""{0}"" does not exist in counter ""{1}"", " & _
"category ""{2}"".", instanceName, counterName, categoryName)
Return
Else
' The instance name exists, now get its InstanceData object
' using the indexer (Item property) for the InstanceDataCollection.
Dim instData As InstanceData = idCol(instanceName)
Console.WriteLine("CategoryName: {0}", categoryName)
Console.WriteLine("CounterName: {0}", counterName)
Console.WriteLine("InstanceName: {0}", instData.InstanceName)
Console.WriteLine("RawValue: {0}", instData.RawValue)
End If
End Sub
Keterangan
Parameter instanceName
tidak peka huruf besar/kecil.
Berlaku untuk
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk