InstanceDataCollectionCollection 类

定义

提供 InstanceDataCollection 对象的强类型集合。

public ref class InstanceDataCollectionCollection : System::Collections::DictionaryBase
public class InstanceDataCollectionCollection : System.Collections.DictionaryBase
type InstanceDataCollectionCollection = class
    inherit DictionaryBase
Public Class InstanceDataCollectionCollection
Inherits DictionaryBase
继承
InstanceDataCollectionCollection

示例

下面的代码示例显示本地计算机上特定 PerformanceCounterCategory 的实例数据。 它首先显示编号的名称 PerformanceCounterCategory 列表。 在用户输入其中一个类别的编号后,该示例将获取 InstanceDataCollectionCollectionPerformanceCounterCategory的 。 然后,它将 属性返回 Values 的集合转换为 对象的数组 InstanceDataCollection 。 该示例显示与每个 InstanceDataInstanceDataCollection关联的实例数据。

using System;
using System.Diagnostics;
using System.Collections;

class InstDataKeysValuesMod
{

    private static string categoryName;

    public static void Main()
    {
        string catNumStr;
        int categoryNum;

        PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories();

        Console.WriteLine("These categories are registered on this computer:");

        int catX;
        for(catX=0; catX<categories.Length; catX++)
        {
            Console.WriteLine("{0,4} - {1}", catX+1, categories[catX].CategoryName);
        }

        // Ask the user to choose a category.
        Console.Write("Enter the category number from the above list: ");
        catNumStr = Console.ReadLine();

        // Validate the entered category number.
        try
        {
            categoryNum = int.Parse(catNumStr);
            if (categoryNum<1||categoryNum>categories.Length)
            {
                throw new Exception(String.Format("The category number must be in the " +
                    "range 1..{0}.", categories.Length));
            }
            categoryName = categories[(categoryNum - 1)].CategoryName;
        }
        catch(Exception ex)
        {
            Console.WriteLine("\"{0}\" is not a valid category number." +
                "\r\n{1}", catNumStr, ex.Message);
            return;
        }

        // 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]);
        }
    }

    // Display the contents of an InstanceDataCollection.
    public static void ProcessInstanceDataCollection(InstanceDataCollection idCol)
    {

        ICollection idColKeys = idCol.Keys;
        string[] idColKeysArray = new string[idColKeys.Count];
        idColKeys.CopyTo(idColKeysArray, 0);

        ICollection idColValues = idCol.Values;
        InstanceData[] idColValuesArray = new InstanceData[idColValues.Count];
        idColValues.CopyTo(idColValuesArray, 0);

        Console.WriteLine("  InstanceDataCollection for \"{0}\" " +
            "has {1} elements.", idCol.CounterName, idCol.Count);

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

    // Display the contents of an InstanceData object.
    public static void ProcessInstanceDataObject(InstanceData instData)
    {
        CounterSample sample = instData.Sample;

        Console.WriteLine("    From InstanceData:\r\n      " +
            "InstanceName: {0,-31} RawValue: {1}", instData.InstanceName, instData.Sample.RawValue);
        Console.WriteLine("    From CounterSample:\r\n      " +
            "CounterType: {0,-32} SystemFrequency: {1}\r\n" +
            "      BaseValue: {2,-34} RawValue: {3}\r\n" +
            "      CounterFrequency: {4,-27} CounterTimeStamp: {5}\r\n" +
            "      TimeStamp: {6,-34} TimeStamp100nSec: {7}", sample.CounterType, sample.SystemFrequency, sample.BaseValue, sample.RawValue, sample.CounterFrequency, sample.CounterTimeStamp, sample.TimeStamp, sample.TimeStamp100nSec);
    }
}
Imports System.Diagnostics
Imports System.Collections

Module InstDataKeysValuesMod

    Private categoryName As String

    Sub Main()
        Dim catNumStr As String
        Dim categoryNum As Integer

        Dim categories As PerformanceCounterCategory() = _
            PerformanceCounterCategory.GetCategories()

        Console.WriteLine( _
            "These categories are registered on this computer:")

        Dim catX As Integer
        For catX = 0 To categories.Length - 1
            Console.WriteLine("{0,4} - {1}", catX + 1, _
                categories(catX).CategoryName)
        Next catX

        ' Ask the user to choose a category.
        Console.Write( _
            "Enter the category number from the above list: ")
        catNumStr = Console.ReadLine()

        ' Validate the entered category number.
        Try
            categoryNum = Integer.Parse(catNumStr)
            If categoryNum < 1 Or categoryNum > categories.Length Then
                Throw New Exception( _
                    String.Format("The category number must be in the " & _
                        "range 1..{0}.", categories.Length))
            End If
            categoryName = categories((categoryNum - 1)).CategoryName

        Catch ex As Exception
            Console.WriteLine("""{0}"" is not a valid category number." & _
                vbCrLf & "{1}", catNumStr, ex.Message)
            Return
        End Try

        ' 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
    End Sub

    ' Display the contents of an InstanceDataCollection.
    Sub ProcessInstanceDataCollection(ByVal idCol As InstanceDataCollection)

        Dim idColKeys As ICollection = idCol.Keys
        Dim idColKeysArray(idColKeys.Count - 1) As String
        idColKeys.CopyTo(idColKeysArray, 0)

        Dim idColValues As ICollection = idCol.Values
        Dim idColValuesArray(idColValues.Count - 1) As InstanceData
        idColValues.CopyTo(idColValuesArray, 0)

        Console.WriteLine("  InstanceDataCollection for ""{0}"" " & _
            "has {1} elements.", idCol.CounterName, idCol.Count)

        ' Display the InstanceDataCollection Keys and Values.
        ' The Keys and Values collections have the same number of elements.
        Dim index As Integer
        For index = 0 To idColKeysArray.Length - 1
            Console.WriteLine("    Next InstanceDataCollection " & _
                "Key is ""{0}""", idColKeysArray(index))
            ProcessInstanceDataObject(idColValuesArray(index))
        Next index
    End Sub

    ' Display the contents of an InstanceData object.
    Sub ProcessInstanceDataObject(ByVal instData As InstanceData)
        Dim sample As CounterSample = instData.Sample

        Console.WriteLine("    From InstanceData:" & vbCrLf & "      " & _
            "InstanceName: {0,-31} RawValue: {1}", _
            instData.InstanceName, instData.Sample.RawValue)
        Console.WriteLine("    From CounterSample:" & vbCrLf & "      " & _
            "CounterType: {0,-32} SystemFrequency: {1}" & vbCrLf & _
            "      BaseValue: {2,-34} RawValue: {3}" & vbCrLf & _
            "      CounterFrequency: {4,-27} CounterTimeStamp: {5}" & vbCrLf & _
            "      TimeStamp: {6,-34} TimeStamp100nSec: {7}", _
            sample.CounterType, sample.SystemFrequency, sample.BaseValue, _
            sample.RawValue, sample.CounterFrequency, sample.CounterTimeStamp, _
            sample.TimeStamp, sample.TimeStamp100nSec)
    End Sub
End Module

注解

InstanceDataCollectionCollection 表示从 方法返回的 ReadCategory 集合。 此集合包含所有计数器和实例数据。 集合包含每个计数器的 对象 InstanceDataCollection 。 每个 InstanceDataCollection 对象都包含该实例的所有计数器的性能数据。 因此,数据按计数器名称编制索引,然后按实例名称编制索引。

构造函数

InstanceDataCollectionCollection()
已过时.
已过时.
已过时.

初始化 InstanceDataCollectionCollection 类的新实例。

属性

Count

获取 DictionaryBase 实例中包含的元素数。

(继承自 DictionaryBase)
Dictionary

获取 DictionaryBase 实例中包含的元素的列表。

(继承自 DictionaryBase)
InnerHashtable

获取 DictionaryBase 实例中包含的元素的列表。

(继承自 DictionaryBase)
Item[String]

获取指定计数器的实例数据。

Keys

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

Values

获取组成计数器实例集合的实例数据值。

方法

Clear()

清除 DictionaryBase 实例的内容。

(继承自 DictionaryBase)
Contains(String)

确定集合中是否存在指定计数器的实例数据集合(由索引 InstanceDataCollection 对象之一来标识)。

CopyTo(Array, Int32)

DictionaryBase 元素复制到位于指定索引处的一维 Array 中。

(继承自 DictionaryBase)
CopyTo(InstanceDataCollection[], Int32)

InstanceDataCollection 实例数组复制到集合中的指定索引处。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetEnumerator()

返回循环访问 IDictionaryEnumerator 实例的 DictionaryBase

(继承自 DictionaryBase)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnClear()

在清除 DictionaryBase 实例的内容之前执行其他自定义进程。

(继承自 DictionaryBase)
OnClearComplete()

在清除 DictionaryBase 实例的内容之后执行其他自定义进程。

(继承自 DictionaryBase)
OnGet(Object, Object)

获取 DictionaryBase 实例中带有指定键和值的元素。

(继承自 DictionaryBase)
OnInsert(Object, Object)

在向 DictionaryBase 实例中插入新元素之前执行其他自定义进程。

(继承自 DictionaryBase)
OnInsertComplete(Object, Object)

在向 DictionaryBase 实例中插入新元素之后执行其他自定义进程。

(继承自 DictionaryBase)
OnRemove(Object, Object)

当从 DictionaryBase 实例移除元素时执行其他自定义进程。

(继承自 DictionaryBase)
OnRemoveComplete(Object, Object)

在从 DictionaryBase 实例中移除元素之后执行其他自定义进程。

(继承自 DictionaryBase)
OnSet(Object, Object, Object)

当在 DictionaryBase 实例中设置值之前执行其他自定义进程。

(继承自 DictionaryBase)
OnSetComplete(Object, Object, Object)

当在 DictionaryBase 实例中设置值后执行其他自定义进程。

(继承自 DictionaryBase)
OnValidate(Object, Object)

在验证具有指定键和值的元素时执行其他自定义进程。

(继承自 DictionaryBase)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

ICollection.IsSynchronized

获取一个值,该值指示对 DictionaryBase 对象的访问是否同步(线程安全)。

(继承自 DictionaryBase)
ICollection.SyncRoot

获取一个对象,该对象可用于同步对 DictionaryBase 对象的访问。

(继承自 DictionaryBase)
IDictionary.Add(Object, Object)

将带有指定键和值的元素添加到 DictionaryBase 中。

(继承自 DictionaryBase)
IDictionary.Contains(Object)

确定 DictionaryBase 是否包含特定键。

(继承自 DictionaryBase)
IDictionary.IsFixedSize

获取一个值,该值指示 DictionaryBase 对象是否具有固定大小。

(继承自 DictionaryBase)
IDictionary.IsReadOnly

获取一个值,该值指示 DictionaryBase 对象是否为只读。

(继承自 DictionaryBase)
IDictionary.Item[Object]

获取或设置与指定的键关联的值。

(继承自 DictionaryBase)
IDictionary.Keys

获取包含 ICollection 对象中的键的 DictionaryBase 对象。

(继承自 DictionaryBase)
IDictionary.Remove(Object)

DictionaryBase 中移除包含指定键的元素。

(继承自 DictionaryBase)
IDictionary.Values

获取 ICollection 对象,它包含 DictionaryBase 对象中的值。

(继承自 DictionaryBase)
IEnumerable.GetEnumerator()

返回循环访问 IEnumeratorDictionaryBase

(继承自 DictionaryBase)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于

另请参阅