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 表示されます。 ユーザーがカテゴリの 1 つの数を入力した後、この例ではそのPerformanceCounterCategory値をInstanceDataCollectionCollection取得します。 その後、返された 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 、カウンターのすべてのインスタンス データを含むコレクションを表します。 このコレクションは、メソッドを使用する InstanceDataCollectionCollection 場合に ReadCategory 含まれています。

コンストラクター

InstanceDataCollection(String)
互換性のために残されています。
互換性のために残されています。
互換性のために残されています。
互換性のために残されています。

(パフォーマンス インスタンスを定義する) 指定したパフォーマンス カウンターを使用して、InstanceDataCollection クラスの新しいインスタンスを初期化します。

プロパティ

Count

DictionaryBase インスタンスに含まれる要素の数を取得します。

(継承元 DictionaryBase)
CounterName

インスタンス データを取得するパフォーマンス カウンターの名前を取得します。

Dictionary

DictionaryBase インスタンスに格納されている要素のリストを取得します。

(継承元 DictionaryBase)
InnerHashtable

DictionaryBase インスタンスに格納されている要素のリストを取得します。

(継承元 DictionaryBase)
Item[String]

このカウンターに関連付けられているインスタンス データを取得します。 通常、これは一連の生のカウンター値です。

Keys

オブジェクトと、インスタンス データに関連付けられているオブジェクトのカウンター レジストリ キーを取得します。

Values

カウンターのインスタンス データを構成する生のカウンター値を取得します。

メソッド

Clear()

DictionaryBase インスタンスの内容を消去します。

(継承元 DictionaryBase)
Contains(String)

(インデックスを作成した InstanceData オブジェクトの 1 つによって識別される) 指定した名前のパフォーマンス インスタンスが、コレクション内に存在しているかどうかを確認します。

CopyTo(Array, Int32)

1 次元の DictionaryBase の指定したインデックスに Array の要素をコピーします。

(継承元 DictionaryBase)
CopyTo(InstanceData[], Int32)

指定した 1 次元配列の指定したインデックス位置に、コレクション内の項目をコピーします。

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

DictionaryBase を反復処理する IEnumerator を返します。

(継承元 DictionaryBase)

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください