Пример #1
0
        private void Flush()
        {
            // Only allow one thread in (non blocking)
            int currentLock = Interlocked.CompareExchange(ref _flushLock, 1, 0);

            if (currentLock == 1)
            {
                return;
            }

            try
            {
                RateDetail current = Interlocked.Exchange(ref _currentRateDetail, new RateDetail(Name));
                current.Stop();
                Report.Enqueue(current);
                return;
            }
            finally
            {
                Interlocked.Exchange(ref _flushLock, 0);
            }
        }
Пример #2
0
        private void DisplaySummary()
        {
            var list = new List <RateDetail>();

            while (_queue.Count > 0)
            {
                RateDetail detail;
                if (_queue.TryDequeue(out detail))
                {
                    detail.Stop();
                    list.Add(detail);
                }
            }

            RateDetail summary = new RateDetail($"Summary ({list.Count})");

            foreach (var item in list)
            {
                summary.Add(item);
            }

            summary.Stop();
            DisplayDetail(summary);
        }