Hi guys:
Calling PerformanceCounterCategory.Create() below on my machine thorws out this exception:
System.ComponentModel.Win32Exception: Access is denied
And the message reported in Event Viewer goes as following:
The SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib key could not be opened or accessed in order to install counter strings.The Win32 status returned by the call is the first DWORD in Data section.
Do you know what's the issue about it?
Thank you!
if (!PerformanceCounterCategory.Exists("MyCategory"))
{
CounterCreationDataCollection counters = new CounterCreationDataCollection();
CounterCreationData avgDurationBase = new CounterCreationData();
avgDurationBase.CounterName = "average time per operation base";
avgDurationBase.CounterHelp = "Average duration per operation execution base";
avgDurationBase.CounterType = PerformanceCounterType.AverageBase;
counters.Add(avgDurationBase);
// create new category with the counters above
PerformanceCounterCategory.Create("MyCategory",
"Sample category for Codeproject", PerformanceCounterCategoryType.SingleInstance, counters);
}