public PerSecondScheduler(ILogger logger, int tasksCount = 30, int inSeconds = 1)
 {
     _logger     = logger;
     _tasksCount = tasksCount;
     _inSeconds  = inSeconds;
     _innerDelay = ((1000 * _inSeconds) / _tasksCount) + 1;
     _queue      = new MultiLevelPriorityQueue <Task>();
     _semaphore  = new Semaphore(_tasksCount, _tasksCount);
     _thread     = new Thread(Start);
     _thread.Start();
 }
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _runThread = false;
                    _thread.Interrupt();
                    _thread.Join();
                    lock (_queue)
                    {
                        _queue.Dispose();
                    }
                }
                _thread       = null;
                _queue        = null;
                disposedValue = true;
            }
        }