I have a WCF service that updates the value of two performance counters. The first is defined as NumberOfItems64, and the second as RateOfCountsPerSecond64. When I update their values (I do this several times per second), perfmon displays as expected the right value for the first counter, but always says that the value of the second counter is 0. When I debug my code, I can see that the RawValue property of the second counter is updated as expected...
Here is my PowerShell code to create the counters :
$categoryName = "My category"
$exists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)
if ($exists)
{
[System.Diagnostics.PerformanceCounterCategory]::Delete($categoryName)
}
$counters = new-object System.Diagnostics.CounterCreationDataCollection
$counter = new-object System.Diagnostics.CounterCreationData
$counter.CounterType = [System.Diagnostics.PerformanceCounterType]::NumberOfItems64
$counter.CounterName = "# ops"
$counters.Add($counter)
$counter = new-object System.Diagnostics.CounterCreationData
$counter.CounterType = [System.Diagnostics.PerformanceCounterType]::RateOfCountsPerSecond64
$counter.CounterName = "# ops/sec"
$counters.Add($counter)
[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, $categoryName, [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance, $counters)
Here is my code to update the value of the counters :
long value = GetValue();
counter1.IncrementBy(value);
counter2.IncrementBy(value);
I found on StackOverflow this question, that looks pretty similar to mine : Counter of type RateOfCountsPerSecond32 always shows 0 but it doesn't resolve my problem.
Any idea ?
After a restart of my computer, my code works as expected... Strange !!!!!!!