InstanceDataCollectionCollection.Keys 屬性

定義

為與這個執行個體資料集合相關聯的物件取得物件和計數器登錄機碼 (Registry Key)。

public:
 property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
public System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
Public ReadOnly Property Keys As ICollection

屬性值

ICollection,表示一組物件特定的登錄機碼。

範例

下列程式代碼範例會 Keys 使用 的 InstanceDataCollectionCollection 屬性傳回計數器名稱的集合,它會轉換成 的 String陣列。 它會使用 Values 屬性產生 物件的陣列InstanceDataCollection。 針對計數器名稱陣列中的每個專案,它會顯示名稱,並呼叫函式來處理相關聯的 InstanceDataCollection


// Process the InstanceDataCollectionCollection for this category.
PerformanceCounterCategory pcc = new PerformanceCounterCategory(categoryName);
InstanceDataCollectionCollection idColCol = pcc.ReadCategory();

ICollection idColColKeys = idColCol.Keys;
string[] idCCKeysArray = new string[idColColKeys.Count];
idColColKeys.CopyTo(idCCKeysArray, 0);

ICollection idColColValues = idColCol.Values;
InstanceDataCollection[] idCCValuesArray = new InstanceDataCollection[idColColValues.Count];
idColColValues.CopyTo(idCCValuesArray, 0);

Console.WriteLine("InstanceDataCollectionCollection for \"{0}\" " +
    "has {1} elements.", categoryName, idColCol.Count);

// Display the InstanceDataCollectionCollection Keys and Values.
// The Keys and Values collections have the same number of elements.
int index;
for(index=0; index<idCCKeysArray.Length; index++)
{
    Console.WriteLine("  Next InstanceDataCollectionCollection " +
        "Key is \"{0}\"", idCCKeysArray[index]);
    ProcessInstanceDataCollection(idCCValuesArray[index]);
}

' Process the InstanceDataCollectionCollection for this category.
Dim pcc As New PerformanceCounterCategory(categoryName)
Dim idColCol As InstanceDataCollectionCollection = pcc.ReadCategory()

Dim idColColKeys As ICollection = idColCol.Keys
Dim idCCKeysArray(idColColKeys.Count - 1) As String
idColColKeys.CopyTo(idCCKeysArray, 0)

Dim idColColValues As ICollection = idColCol.Values
Dim idCCValuesArray(idColColValues.Count - 1) As InstanceDataCollection
idColColValues.CopyTo(idCCValuesArray, 0)

Console.WriteLine("InstanceDataCollectionCollection for ""{0}"" " & _
    "has {1} elements.", categoryName, idColCol.Count)

' Display the InstanceDataCollectionCollection Keys and Values.
' The Keys and Values collections have the same number of elements.
Dim index As Integer
For index = 0 To idCCKeysArray.Length - 1
    Console.WriteLine("  Next InstanceDataCollectionCollection " & _
        "Key is ""{0}""", idCCKeysArray(index))
    ProcessInstanceDataCollection(idCCValuesArray(index))
Next index

備註

每個軟體元件會在安裝物件和計數器時為其物件和計數器建立密鑰,並在執行時寫入計數器數據。 您可以存取此數據,就像存取任何其他登錄數據一樣。 不過,雖然您使用登錄來收集效能數據,但數據不會儲存在登錄資料庫中。 相反地,系統會從適當的系統物件管理員收集數據。

適用於