Esempio n. 1
0
        private float GetValue()
        {
            CounterSample currentSample = _perfCounter.NextSample();

            if (currentSample.SystemFrequency != 0)
            {
                // The recommended delay time between calls to the NextSample method is one second, to allow the counter to perform the next incremental read.
                float timeDifferenceSecs = (currentSample.TimeStamp - _nextSample.TimeStamp) / (float)currentSample.SystemFrequency;
                if (timeDifferenceSecs > 0.5F || timeDifferenceSecs < -0.5F)
                {
                    _prevSample = _nextSample;
                    _nextSample = currentSample;
                    if (_prevSample.Equals(CounterSample.Empty))
                    {
                        _prevSample = currentSample;
                    }
                }
            }
            else
            {
                _prevSample = _nextSample;
                _nextSample = currentSample;
            }
            float sampleValue = CounterSample.Calculate(_prevSample, currentSample);

            return(sampleValue);
        }