InstanceDataCollectionCollection 類別

定義

提供 InstanceDataCollection 物件的強類型集合。Provides a strongly typed collection of InstanceDataCollection objects.

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

範例

下列程式碼範例會顯示本機電腦上特定的實例資料 PerformanceCounterCategoryThe following code example displays the instance data for a particular PerformanceCounterCategory on the local computer. 它會先顯示名稱的編號清單 PerformanceCounterCategoryIt first displays a numbered list of PerformanceCounterCategory names. 在使用者輸入其中一個類別的數目之後,此範例會取得該類別的 InstanceDataCollectionCollection PerformanceCounterCategoryAfter the user enters the number of one of the categories, the example gets the InstanceDataCollectionCollection for that PerformanceCounterCategory. 然後,它會將屬性傳回的集合轉換 Values 為物件的陣列 InstanceDataCollectionIt then converts the collection returned by the Values property to an array of InstanceDataCollection objects. 此範例會顯示與每個實例相關聯的實例資料 InstanceData InstanceDataCollectionThe example displays the instance data associated with each InstanceData of each InstanceDataCollection.

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類別代表從方法傳回的集合 ReadCategoryThe InstanceDataCollectionCollection class represents the collection returned from the ReadCategory method. 這個集合包含所有計數器和實例資料。This collection contains all the counter and instance data. 集合包含 InstanceDataCollection 每個計數器的物件。The collection contains an InstanceDataCollection object for each counter. 每個 InstanceDataCollection 物件都包含該實例之所有計數器的效能資料。Each InstanceDataCollection object contains the performance data for all counters for that instance. 因此,資料會依計數器名稱和實例名稱來編制索引。Thus, the data is indexed by counter name and then by instance name.

建構函式

InstanceDataCollectionCollection()
已過時。
已過時。
已過時。

初始化 InstanceDataCollectionCollection 類別的新執行個體。Initializes a new instance of the InstanceDataCollectionCollection class.

屬性

Count

取得 DictionaryBase 執行個體中包含的元素數目。Gets the number of elements contained in the DictionaryBase instance.

(繼承來源 DictionaryBase)
Dictionary

取得包含於 DictionaryBase 執行個體中的項目清單。Gets the list of elements contained in the DictionaryBase instance.

(繼承來源 DictionaryBase)
InnerHashtable

取得包含於 DictionaryBase 執行個體中的項目清單。Gets the list of elements contained in the DictionaryBase instance.

(繼承來源 DictionaryBase)
Item[String]

為指定的計數器取得執行個體資料。Gets the instance data for the specified counter.

Keys

為與這個執行個體資料集合相關聯的物件取得物件和計數器登錄機碼 (Registry Key)。Gets the object and counter registry keys for the objects associated with this instance data collection.

Values

取得構成計數器執行個體集合的執行個體資料數值。Gets the instance data values that comprise the collection of instances for the counter.

方法

Clear()

清除 DictionaryBase 執行個體的內容。Clears the contents of the DictionaryBase instance.

(繼承來源 DictionaryBase)
Contains(String)

判斷指定計數器 (由其中一個索引的 InstanceDataCollection 物件識別) 的執行個體資料集合是否在集合中。Determines whether an instance data collection for the specified counter (identified by one of the indexed InstanceDataCollection objects) exists in the collection.

CopyTo(Array, Int32)

DictionaryBase 元素複製到指定索引的一維 ArrayCopies the DictionaryBase elements to a one-dimensional Array at the specified index.

(繼承來源 DictionaryBase)
CopyTo(InstanceDataCollection[], Int32)

從指定索引處開始,將 InstanceDataCollection 執行個體的陣列複製到集合。Copies an array of InstanceDataCollection instances to the collection, at the specified index.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetEnumerator()

傳回能夠逐一查看 IDictionaryEnumerator 執行個體的 DictionaryBaseReturns an IDictionaryEnumerator that iterates through the DictionaryBase instance.

(繼承來源 DictionaryBase)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
OnClear()

在清除 DictionaryBase 執行個體的內容前,執行額外的自訂處理序。Performs additional custom processes before clearing the contents of the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnClearComplete()

在清除 DictionaryBase 執行個體的內容後,執行額外的自訂處理序。Performs additional custom processes after clearing the contents of the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnGet(Object, Object)

取得 DictionaryBase 執行個體中具有指定索引鍵和值的元素。Gets the element with the specified key and value in the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnInsert(Object, Object)

在將新的元素插入至 DictionaryBase 執行個體前,執行額外的自訂處理序。Performs additional custom processes before inserting a new element into the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnInsertComplete(Object, Object)

在將新的元素插入至 DictionaryBase 執行個體後,執行額外的自訂處理序。Performs additional custom processes after inserting a new element into the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnRemove(Object, Object)

在從 DictionaryBase 執行個體移除元素前,執行額外的自訂處理序。Performs additional custom processes before removing an element from the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnRemoveComplete(Object, Object)

在從 DictionaryBase 執行個體移除元素後,執行額外的自訂處理序。Performs additional custom processes after removing an element from the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnSet(Object, Object, Object)

DictionaryBase 執行個體中設定數值前,執行額外的自訂處理序。Performs additional custom processes before setting a value in the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnSetComplete(Object, Object, Object)

DictionaryBase 執行個體中設定數值後,執行額外的自訂處理序。Performs additional custom processes after setting a value in the DictionaryBase instance.

(繼承來源 DictionaryBase)
OnValidate(Object, Object)

在使用指定的索引鍵及值驗證元素時,執行額外的自訂處理序。Performs additional custom processes when validating the element with the specified key and value.

(繼承來源 DictionaryBase)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

ICollection.IsSynchronized

取得值,指出對 DictionaryBase 物件的存取是否為同步的 (執行緒安全)。Gets a value indicating whether access to a DictionaryBase object is synchronized (thread safe).

(繼承來源 DictionaryBase)
ICollection.SyncRoot

取得可用來同步存取 DictionaryBase 物件的物件。Gets an object that can be used to synchronize access to a DictionaryBase object.

(繼承來源 DictionaryBase)
IDictionary.Add(Object, Object)

將有指定索引鍵和數值的項目加入 DictionaryBaseAdds an element with the specified key and value into the DictionaryBase.

(繼承來源 DictionaryBase)
IDictionary.Contains(Object)

判斷 DictionaryBase 是否包含特定索引鍵。Determines whether the DictionaryBase contains a specific key.

(繼承來源 DictionaryBase)
IDictionary.IsFixedSize

取得值,指出 DictionaryBase 物件是否具有固定的大小。Gets a value indicating whether a DictionaryBase object has a fixed size.

(繼承來源 DictionaryBase)
IDictionary.IsReadOnly

取得值,指出 DictionaryBase 物件是否為唯讀。Gets a value indicating whether a DictionaryBase object is read-only.

(繼承來源 DictionaryBase)
IDictionary.Item[Object]

取得或設定與指定之索引鍵相關聯的值。Gets or sets the value associated with the specified key.

(繼承來源 DictionaryBase)
IDictionary.Keys

取得 ICollection 物件,其中包含 DictionaryBase 物件中的索引鍵。Gets an ICollection object containing the keys in the DictionaryBase object.

(繼承來源 DictionaryBase)
IDictionary.Remove(Object)

將有指定索引鍵的項目從 DictionaryBase 移除。Removes the element with the specified key from the DictionaryBase.

(繼承來源 DictionaryBase)
IDictionary.Values

取得 ICollection 物件,其中含有 DictionaryBase 物件中的值。Gets an ICollection object containing the values in the DictionaryBase object.

(繼承來源 DictionaryBase)
IEnumerable.GetEnumerator()

傳回透過 IEnumerator 重複的 DictionaryBaseReturns an IEnumerator that iterates through the DictionaryBase.

(繼承來源 DictionaryBase)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱