InstanceDataCollectionCollection.Keys 属性

定义

获取对象和与该实例数据集合关联的对象的计数器注册表项。

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

示例

下面的代码示例使用 KeysInstanceDataCollectionCollection 属性返回计数器名称的集合,该集合将转换为 数组 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

注解

每个软件组件在安装时为其对象和计数器创建密钥,并在执行时写入计数器数据。 你可以像访问任何其他注册表数据一样访问此数据。 但是,尽管使用注册表来收集性能数据,但数据不会存储在注册表数据库中。 相反,系统会从相应的系统对象管理器收集数据。

适用于