performance counter instance

  • Thread starter Thread starter Kristofer Andersson
  • Start date Start date
K

Kristofer Andersson

How do I create a new instance in a performance counter category? The
PerformanceCounterCategory class only has InstanceExists but I can not find
a way to create a new instance..?
 
Try -

PerformanceCounter instance = new PerformanceCounter("Category name",
"counter name", "instance name", false);
Note that the instance won't actually show up until it first gets a value.

rajasi
 
performancecounter is different from performancecountercategory, you can
only create new performance counter
 
Yup, that is what I am doing. But I got confused by a bug in the
PerformanceCounter class or Windows. If a counter has been created and
received a value without instance name and is subsequently created with
instance name and get a value, the named instance will not be created. After
a reboot of the machine and creating instance name only counters it works.
 
I don't know that that is a bug. When you create a counter and don't specify
the instance name, a single instance counter is created. You won't then be
able to create other instances.
 
Yup, but if it can't be created shouldn't the framework at least throw an
exception?
 
Back
Top