public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;
            _lockManager?.Dispose();
            _lockManager = null;
        }
        internal TaskManager(Func <ITaskRepository> repositoryFactory, TaskManagerOptions options = null)
        {
            options      = options ?? TaskManagerOptions.Default;
            _lockManager = new LockManager(repositoryFactory, minTimeout: new TimeSpan(TimeSpan.TicksPerSecond));

            _repositoryFactory = repositoryFactory;
            _clockProvider     = _lockManager.ClockProvider;
            _listener          = new TaskManagerListener(this, options.MainLoopWait, options.MaxWorkerThreads);

            using (var repository = repositoryFactory())
            {
                _connectionString = repository.Database.Connection.ConnectionString;
            }
        }