I tried to find out why some performance counters are not updated on our production server when I got into this strange problem. It seems that the counter returns different values RawValuewhen it is not read-only. When it is read-only, it is always zero, when it is not read-only, it shows different values.
Here is my PowerShell session showing this:
PS C:\Users\doron> $counter = new-object Diagnostics.PerformanceCounter
PS C:\Users\doron> $counter.CategoryName = "My category"
PS C:\Users\doron> $counter.CounterName = "My counter name"
PS C:\Users\doron> $counter.ReadOnly = 1
PS C:\Users\doron> $counter
CategoryName : My category
CounterHelp : My counter name
CounterName : My counter name
CounterType : NumberOfItems64
InstanceLifetime : Global
InstanceName :
ReadOnly : True
MachineName : .
RawValue : 0
Site :
Container :
PS C:\Users\doron> $counter.ReadOnly = 0
PS C:\Users\doron> $counter
CategoryName : My category
CounterHelp : My counter name
CounterName : My counter name
CounterType : NumberOfItems64
InstanceLifetime : Global
InstanceName :
ReadOnly : False
MachineName : .
RawValue : 20
Site :
Container :
PS C:\Users\doron> $counter.ReadOnly = 1
PS C:\Users\doron> $counter
CategoryName : My category
CounterHelp : My counter name
CounterName : My counter name
CounterType : NumberOfItems64
InstanceLifetime : Global
InstanceName :
ReadOnly : True
MachineName : .
RawValue : 0
Site :
Container :
Server is Windows 2008 R2 running under .NET 4.5.
, , ( , ). RawValue , ReadOnly .
, ?