When querying instances for the the “Process” performance counter category there might be multiple instances of of a process with the same name.
For example this code:
var cat = new PerformanceCounterCategory("Process");
var names = cat.GetInstanceNames();
foreach (var name in names)
Console.WriteLine(name);
Might print these results:
…
iexplore
iexplore#1
iexplore#2
iexplore#3
…
How do I know which process each of these counter instances corresponds to?
There is a PerformanceCounter named “ID Process” in the “Process” category that will return the pid of the process that the performance counter instance corresponds to.
This will print: