Does anyone have a quick example of creating performanceCounters for each Processor on a machine,all the ones I have send are complex and I'm sure there must be a simple way. I know how to list all the CatergoryNames, it the listing of the instances within the Catergories that I am having trouble with.
Cheers ![]()

anyone have a simple exmaple to map all instances of CPU in performanceCounter
Luis Esteban Valencia Muñoz
Hi,
No problem, this example is useful to enumerate the instances:
PerformanceCounterCategory Cat = new PerformanceCounterCategory("Processors", "YourRemoteMachine");
string[] Instances = Cat.GetInstanceNames();
CPUs = new PerformanceCounter[Instances.Length];
for (int i = 0; i < CPUs.Length; i++)
{
CPUs[ i ] = new PerformanceCounter("Processor", "% Processor Time", Instances[ i ], "YourRemoteMachine");
}
Cheers
kastanienreis
kjm0001
Hi,
Quick example Maybe this one:
CPUs =
new PerformanceCounter[System.Environment.ProcessorCount]; for (int i = 0; i < CPUs.Length; i++){
CPUs[ i ] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
}
Let me know if you need more information.
Regards
swingme
Thanks, I couldn't get your code to work, I know it would be something little but just couldn't work it out. It did point in the right direction and this is the final code I came up with
PerformanceCounterCategory Cat = new PerformanceCounterCategory("Processor","EZ0526"); string[] Instances = Cat.GetInstanceNames(); //get all the instances of Counter Processors Array.Sort(Instances); //sort the array in order foreach (string Instance in Instances) //read each Instance in the arraylistBox1.Items.Add(Instance);