共用方式為


InstanceDataCollection 類別

定義

提供 InstanceData 物件的強類型集合。

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

範例

下列程式代碼範例會顯示本機計算機上的特定 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

備註

類別 InstanceDataCollection 代表集合,其中包含計數器的所有實例數據。 使用 ReadCategory 方法時,這個集合包含在 InstanceDataCollectionCollection 中。

建構函式

InstanceDataCollection(String)
已淘汰.
已淘汰.
已淘汰.

使用指定的效能計數器 (會定義效能執行個體),初始化 InstanceDataCollection 類別的新執行個體。

屬性

Count

取得 DictionaryBase 執行個體中包含的元素數目。

(繼承來源 DictionaryBase)
CounterName

取得您要取得之執行個體資料的效能計數器名稱。

Dictionary

取得包含於 DictionaryBase 執行個體中的項目清單。

(繼承來源 DictionaryBase)
InnerHashtable

取得包含於 DictionaryBase 執行個體中的項目清單。

(繼承來源 DictionaryBase)
Item[String]

取得與這個計數器相關聯的執行個體資料。 通常是一組未經處理的計數器值。

Keys

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

Values

取得未經處理的計數器值,這些數值構成計數器的執行個體資料。

方法

Clear()

清除 DictionaryBase 執行個體的內容。

(繼承來源 DictionaryBase)
Contains(String)

判斷有指定名稱的效能執行個體 (由其中一個索引的 InstanceData 物件識別) 是否在集合中。

CopyTo(Array, Int32)

DictionaryBase 元素複製到指定索引的一維 Array

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

將集合中的項目複製到指定之一維陣列的指定索引處。

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

適用於

另請參閱