The reason for not getting any exceptions is the try-catch block. If you add your statements in a try and catch block, like this
try { const string _categoryName = "MyPerformanceCounter"; if (!PerformanceCounterCategory.Exists(_categoryName)) { CounterCreationDataCollection counters = new CounterCreationDataCollection(); CounterCreationData ccdWorkingThreads = new CounterCreationData(); ccdWorkingThreads.CounterName = "# working threads"; ccdWorkingThreads.CounterHelp = "Total number of operations executed"; ccdWorkingThreads.CounterType = PerformanceCounterType.NumberOfItems32; counters.Add(ccdWorkingThreads);
Then it will catch exceptions. If you see an exception like "Requested registry access is not allowed." then you need administrative rights to do this. To confirm this, run Visual Studio as an administrator and execute the code.
Vishal
source share