views:

440

answers:

2

Hi

I have created a PerformanceCounterCategory like below

var category = PerformanceCounterCategory.Create("MyCat", "Cat Help", PerformanceCounterCategoryType.SingleInstance, "MyCounter", "Counter Help);

Now i would like to add a new counter to the category to monitor another item but i can't find the api call to do it.

Any Ideas?

A: 
PerformanceCounter lCounter = new PerformanceCounter(Category, CounterName, 
                                                     false);
lCounter.MachineName = ".";
Vasu Balakrishnan
Thanks I will try that when i fire my work laptop up in the morning
Kev Hunter
That does not seem to work
Kev Hunter
First setup your CounterCategory with all the counters and their type as belowvar lCounters = new CounterCreationDataCollection();lCounters.Add(new CounterCreationData(lCounterName, lounterHelp, lCounterType));PerformanceCounterCategory.Create(pCategory, lCategoryHelp, PerformanceCounterCategoryType.SingleInstance, lCounters);Then when you want an instance of the counter, check if the category / counter exists and then do the following....var lCounter = new PerformanceCounter(pCategory, pCounterName, false);lCounter.MachineName = ".";Hope this helps.
Vasu Balakrishnan
+2  A: 

I did a research on this a while back and it doesn't seem to be possible to add counters to an existing category, what you would have to do it to recreate the same category with addition of the new counter.

Keivan
This is what i ended up doing
Kev Hunter