共用方式為


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

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

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()

傳回透過 IEnumerator 重複的 DictionaryBase

(繼承來源 DictionaryBase)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱