/// <summary> /// Ensures the queued workers are stopped and disposed. /// </summary> public void Dispose() { if (!isDisposed) { if (watcher != null) { watcher.EnableRaisingEvents = false; watcher.Dispose(); watcher = null; } if (queue != null) { queue.Dispose(); queue = null; } if (worker != null) { if (worker.IsBusy) { worker.CancelAsync(); } worker.Dispose(); worker = null; } if (catalog != null) { catalog.Dispose(); catalog = null; } if (actives != null) { actives.Clear(); actives = null; } if (disabled != null) { disabled.Clear(); disabled = null; } if (cleansed != null) { cleansed.Clear(); cleansed = null; } controller = null; isDisposed = true; GC.SuppressFinalize(this); } }
private SafeCollection <IScanner> actives; // all queued or running scanners //======================================================================================== // Constructors //======================================================================================== /// <summary> /// Private singleton constructor. /// </summary> private Librarian(Controller controller) { this.controller = controller; this.queue = new BlockingQueue <IScanner>(); this.actives = new SafeCollection <IScanner>(); this.cleansed = new StringCollection(); this.disabled = new StringCollection(); this.scanner = null; this.sync = new Object(); // temporarily reference an empty catalog this.catalog = new TerseCatalog(); this.worker = new BackgroundWorker(); this.worker.DoWork += new DoWorkEventHandler(DoWork); this.worker.ProgressChanged += new ProgressChangedEventHandler(DoProgressChanged); this.worker.WorkerReportsProgress = true; this.worker.WorkerSupportsCancellation = true; this.worker.RunWorkerAsync(); AddScanner(new InitializingScanner(controller, this), InitializingScannerPriority); }