/// <summary>
        /// Provides the observer with new data.
        /// </summary>
        /// <param name="value">The current notification information.</param>
        public override void OnNext(TSource value)
        {
            if (IsRunning)
            {
                var totalCount = Interlocked.Increment(ref _totalCount);

                AnalysisResultsSubject.OnNext(new ThroughputAnalysisResult(totalCount, ElapsedTime));
            }
        }
        /// <summary>
        /// Starts the underlying timer.
        /// </summary>
        public void StartTimer()
        {
            if (IsRunning)
            {
                throw new InvalidOperationException("The Timer is already running and can only be started once.");
            }

            // using an Observable.Interval subscription as timer
            IntervalSubscription = (Scheduler != null ? Observable.Interval(Resolution, Scheduler) : Observable.Interval(Resolution))
                                   .Subscribe(_ =>
            {
                // and on every interval we capture and reset the counter
                var currentCountBeforeReset = Interlocked.Exchange(ref _currentCount, 0);

                // and expose its current value
                AnalysisResultsSubject.OnNext(new ThroughputAnalysisResult(currentCountBeforeReset, Resolution));
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Provides the observer with new data.
        /// </summary>
        /// <param name="value">The current notification information.</param>
        public override void OnNext(TSource value)
        {
            var currentCount = Interlocked.Increment(ref _currentCount);

            AnalysisResultsSubject.OnNext(new CountAnalysisResult(currentCount));
        }