InstanceDataCollection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供 InstanceData 对象的强类型集合。
public ref class InstanceDataCollection : System::Collections::DictionaryBase
public class InstanceDataCollection : System.Collections.DictionaryBase
type InstanceDataCollection = class
inherit DictionaryBase
Public Class InstanceDataCollection
Inherits DictionaryBase
- 继承
示例
下面的代码示例显示本地计算机上的特定 PerformanceCounterCategory 实例数据。 它首先显示编号的名称 PerformanceCounterCategory 列表。 在用户输入其中一个类别的编号后,该示例将获取 InstanceDataCollectionCollection 该 PerformanceCounterCategory的 。 然后,它将 返回 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 |
获取组成计数器实例数据的原始计数器值。 |
方法
显式接口实现
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。 |