/// <summary>
        /// Dispose scanner.
        /// </summary>
        public void Dispose()
        {
            var j = job;

            j?.Dispose();
            job = null;
        }
        /// <summary>
        /// Create scanner that uses patterns.
        /// </summary>
        /// <param name="fileProvider"></param>
        /// <param name="rootPrefix"></param>
        /// <param name="patterns"></param>
        /// <param name="taskFactory"></param>
        /// <param name="errors"></param>
        /// <param name="directoryEvaluator"></param>
        /// <param name="returnDirectories"></param>
        /// <param name="returnFiles"></param>
        public PatternScanner(IFileProvider fileProvider, string rootPrefix, IEnumerable <KeyValuePair <string, PatternSet> > patterns, TaskFactory taskFactory, IProducerConsumerCollection <Exception> errors, Func <string, bool> directoryEvaluator, bool returnDirectories, bool returnFiles)
        {
            this.fileProvider       = fileProvider;
            this.rootPrefix         = rootPrefix;
            this.directoryEvaluator = directoryEvaluator;
            this.paths             = new List <KeyValuePair <string, PatternSet> >(patterns);
            this.job               = new ScanJob(fileProvider, rootPrefix, paths, errors, taskFactory, directoryEvaluator, returnDirectories, returnFiles);
            this.taskFactory       = taskFactory;
            this.returnDirectories = returnDirectories;
            this.returnFiles       = returnFiles;
            int count = Math.Max(1, paths.Count);

            for (int i = 0; i < count; i++)
            {
                taskFactory.StartNew(this.job.Scan);
            }
        }
        /// <summary>
        /// Start over.
        /// </summary>
        public void Reset()
        {
            var j = job;

            if (j == null)
            {
                throw new ObjectDisposedException(nameof(PatternScanner));
            }
            ScanJob newJob = new ScanJob(fileProvider, rootPrefix, paths, errors, taskFactory, directoryEvaluator, returnDirectories, returnFiles);

            j = Interlocked.Exchange(ref job, newJob);
            int count = Math.Max(1, paths.Count);

            for (int i = 0; i < count; i++)
            {
                taskFactory.StartNew(this.job.Scan);
            }
            j.Dispose();
        }