public void WaitCompleted(int timeoutSeconds = 60)
        {
            var chainSec       = new TimeSpan(0, 0, timeoutSeconds);
            var chainLimitTime = new TimeSpan(DateTime.Now.Add(chainSec).Ticks);

            _chainCounter.Wait((int)chainSec.TotalMilliseconds);

            _queueWorker.Complete();

            _cancellationTokenSource.Cancel();

            var chainCurrentTime = new TimeSpan(DateTime.Now.Ticks);
            var chainDelta       = chainLimitTime - chainCurrentTime;

            var timeout = new TimeSpan(0, 0, chainDelta <= TimeSpan.Zero ? 1 : (int)chainDelta.TotalMilliseconds);

            var limitTime = new TimeSpan(DateTime.Now.Add(timeout).Ticks);

            _queueWorker.WaitCompleted((int)timeout.TotalMilliseconds);

#if TRACE_STOP
            Trace.WriteLine("queue completed");
#endif
            var currentTime = new TimeSpan(DateTime.Now.Ticks);
            var delta       = limitTime - currentTime;

            if (delta > TimeSpan.Zero)
            {
#if TRACE_STOP
                Trace.WriteLine($"stop process with {(int)delta.TotalMilliseconds}, sec: {(int)delta.TotalSeconds}");
#endif
                _processCount.Wait((int)delta.TotalMilliseconds);
#if TRACE_STOP
                Trace.WriteLine("process completed");
#endif
            }
        }
Exemple #2
0
 public void Wait(int millisecondsTimeout)
 {
     _counterBlocked.Wait(millisecondsTimeout);
 }