B
B
Boris the Animal2016-06-27 10:38:42
Programming
Boris the Animal, 2016-06-27 10:38:42

Windows NT performance counters. If you try to delete the counters when starting Windows?

If they are deleted, is it possible later that an exception will be thrown, that something is wrong in the registry and it will not be possible to create the same counters again? I read on MSDN that it is not recommended to create counters when Windows starts .
Or maybe, when the counters are not yet initialized, they cannot be deleted? As I understand it, the following may have happened: the OS loaded, my application tried to delete the counters at the start of the service (my application), and it turned out to be done, but, apparently, somehow not completely?
This is the error that occurs when trying to delete performance counters.

25 Jun 2016 10:00:00.5727|Error|Monitoring|||Execute|Параметр реестра имеет неверное значение|   в System.Diagnostics.PerformanceCounterLib.RegisterFiles(String arg0, Boolean unregister)
   в System.Diagnostics.PerformanceCounterLib.UnregisterCategory(String categoryName)
   в System.Diagnostics.PerformanceCounterCategory.Delete(String categoryName)
   в PerformanceMonitor.PerformanceCategory.DeleteIfExists()
   в PerformanceMonitor.MonitoringDispatcher.Initialize(Boolean recreateExistingCategories)
   в CustomServer.Threads.Monitoring.Execute()

These are my classes:
CustomServer.Threads.Monitoring
PerformanceMonitor.PerformanceCategory
This is how counters are created and removed:
_
        public bool DeleteIfExists()
        {
            if (PerformanceCounterCategory.Exists(Name))
            {
                PerformanceCounterCategory.Delete(Name);
                return true;
            }

            return false;
        }

        public bool CreateIfNotExists()
        {
            if (!PerformanceCounterCategory.Exists(Name))
            {
                var counters = new CounterCreationDataCollection();
                foreach (PerformanceSet set in this.counterSets)
                {
                    foreach (CounterCreationDataExt creationData in set.CounterCreationData)
                    {
                        counters.Add(creationData);
                    }
                }

                PerformanceCounterCategory.Create(Name, Description, CategoryType, counters);
                return true;
            }

            return false;
        }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question