Probably a rookie error, but i'm getting something strange. i'm trying to weave a .NET performance counter into an application.
When i call the incrementBy(value)
method on my avg performance counter it is changing the RawValue of my base counter by value as well. i checked the variable names and think everything is correct.
Then when i call increment()
on my base counter it adds 1 to the rawvalue of the avgcounter as well as incrementing the base counter... adding insult to injury!
Has anyone else seen this kind of behavior? Any suggestions for what's going on and how to fix it?
In code i'm using two different counters to measure the time a merge sort i wrote takes. i have a instantaneous counter for the elapsed time of the sort and an average counter.
Dim timePiece As New Stopwatch()
timePiece.Start()
MergeSort()
timePiece.Stop()
ElapsedCounter.RawValue = timePiece.ElapsedMilliseconds
AvgCounter.IncrementBy(timePiece.ElapsedMilliseconds)
AvgCounterBase.Increment()
What i'm seeing occur is:
'Elapsed counter works as expected
'AvgCounter RawValue is 7, AvgCounterBase RawValue is also 7 before incrementing
AvgCounter.IncrementBy(value) 'AvgCounter.RV is 7+value, AvgCounterBase is 7+value AvgCounterBase.Increment() 'AvgCounter.RV is 7+value+1, AvgCounterBase is 7+value+1
i think i may be using the counters wrong, but why does changing the rawvalue of the average seem to also change the rawvalue of the base? i dont think that's supposed to happen.