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