internal void EnsureCounters() { if (PerformanceCounterCategory.Exists(Category)) { bool same = true; try { PerformanceCounterCategory cat = new PerformanceCounterCategory(Category); same = (cat.CategoryType == CategoryType); } catch //maybe delete by others as well { } if (same) { if (counterConfigs != null) { foreach (PerfCounterConfig config in counterConfigs) { if (!CounterExists(config.Name, Category)) { same = false; break; } } } } if (!same) { RemoveCategory(Category); InstallCounters(); } } else InstallCounters(); if (counterConfigs != null) { defaultInstanceCounters = CreatePerfCounters(null); } }
private PerformanceCounterCollection CreatePerfCounters(string instance) { PerformanceCounterCollection counters = new PerformanceCounterCollection(); foreach (PerfCounterConfig config in counterConfigs) { var perfCounter = CounterFromConfig(instance, config); if (perfCounter != null) counters.AddCounter(perfCounter); } return counters; }