G
Guest
Hi to all
I was trying to create a performance counter instance, but I can see the counter but it does not have any instance. Do you know what is the problem
// Delete performance counter category if this exist
if (PerformanceCounterCategory.Exists("Test Counters")
PerformanceCounterCategory.Delete("Test Counters")
// Create a new Test counte
CounterCreationData performanceDataCounter = new CounterCreationData()
performanceDataCounter.CounterType = PerformanceCounterType.NumberOfItems32
performanceDataCounter.CounterName = "Test counter"
performanceDataCounter.CounterHelp = "Contains test counters."
CounterCreationDataCollection countersCollection = new CounterCreationDataCollection()
countersCollection.Add(performanceDataCounter)
PerformanceCounterCategory.Create("Test Counters", "Test performance counters", countersCollection)
// Initialize counter
PerformanceCounter pcPerformanceDataCounters = new PerformanceCounter("Test Counters", "Test counter", "Total", false)
// Set first valu
pcPerformanceDataCounters.RawValue = 0
// Create another read-only counter to verify the previous counte
PerformanceCounter pcPerformanceDataCountersValidator = new PerformanceCounter("Test Counters", "Test counter", "_Total")
Console.WriteLine("Set performance counter value: " + pcPerformanceDataCountersValidator.NextSample().ToString())
When I run this application I get the exception message "Category does not exist." when I instantiate the pcPerformanceDataCountersValidator object (This is because the previous instance counter was not created)
Thanks for your time . . .
I was trying to create a performance counter instance, but I can see the counter but it does not have any instance. Do you know what is the problem
// Delete performance counter category if this exist
if (PerformanceCounterCategory.Exists("Test Counters")
PerformanceCounterCategory.Delete("Test Counters")
// Create a new Test counte
CounterCreationData performanceDataCounter = new CounterCreationData()
performanceDataCounter.CounterType = PerformanceCounterType.NumberOfItems32
performanceDataCounter.CounterName = "Test counter"
performanceDataCounter.CounterHelp = "Contains test counters."
CounterCreationDataCollection countersCollection = new CounterCreationDataCollection()
countersCollection.Add(performanceDataCounter)
PerformanceCounterCategory.Create("Test Counters", "Test performance counters", countersCollection)
// Initialize counter
PerformanceCounter pcPerformanceDataCounters = new PerformanceCounter("Test Counters", "Test counter", "Total", false)
// Set first valu
pcPerformanceDataCounters.RawValue = 0
// Create another read-only counter to verify the previous counte
PerformanceCounter pcPerformanceDataCountersValidator = new PerformanceCounter("Test Counters", "Test counter", "_Total")
Console.WriteLine("Set performance counter value: " + pcPerformanceDataCountersValidator.NextSample().ToString())
When I run this application I get the exception message "Category does not exist." when I instantiate the pcPerformanceDataCountersValidator object (This is because the previous instance counter was not created)
Thanks for your time . . .