本文整理汇总了C#中System.Diagnostics.InstanceDataCollectionCollection.Item属性的典型用法代码示例。如果您正苦于以下问题:C# InstanceDataCollectionCollection.Item属性的具体用法?C# InstanceDataCollectionCollection.Item怎么用?C# InstanceDataCollectionCollection.Item使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Diagnostics.InstanceDataCollectionCollection
的用法示例。
在下文中一共展示了InstanceDataCollectionCollection.Item属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
// The following values can be used as arguments.
string categoryName = "Process";
string counterName = "Private Bytes";
InstanceDataCollectionCollection idColCol;
// Copy the supplied arguments into the local variables.
try
{
categoryName = args[0];
counterName = args[1];
}
catch
{
// Ignore the exception from non-supplied arguments.
}
try
{
// Get the InstanceDataCollectionCollection for this category.
PerformanceCounterCategory pcc = new PerformanceCounterCategory(categoryName);
idColCol = pcc.ReadCategory();
}
catch(Exception ex)
{
Console.WriteLine("An error occurred getting the InstanceDataCollection for " +
"category \"{0}\"."+ "\n" +ex.Message, categoryName);
return;
}
// Check if this counter name exists using the Contains
// method of the InstanceDataCollectionCollection.
if (!idColCol.Contains(counterName))
{
Console.WriteLine("Counter \"{0}\" does not exist in category \"{1}\".", counterName, categoryName);
return;
}
else
{
// Now get the counter's InstanceDataCollection object using the
// indexer (Item property) for the InstanceDataCollectionCollection.
InstanceDataCollection countData = idColCol[counterName];
ICollection idColKeys = countData.Keys;
string[] idColKeysArray = new string[idColKeys.Count];
idColKeys.CopyTo(idColKeysArray, 0);
Console.WriteLine("Counter \"{0}\" of category \"{1}\" " +
"has {2} instances.", counterName, categoryName, idColKeys.Count);
// Display the instance names for this counter.
int index;
for(index=0; index<idColKeysArray.Length; index++)
{
Console.WriteLine("{0,4} -- {1}", index+1, idColKeysArray[index]);
}
}
}