public void Dispose() { if (this.disposed) { return; } this.disposed = true; if (!this.etlProducerSettings.ProcessingWinFabEtlFiles) { string applicationType = this.etlProducerSettings.ApplicationType; lock (ProducerWorkers) { EtlProducerWorkerInfo workerInfo = ProducerWorkers.FirstOrDefault(w => w.ApplicationType.Equals( applicationType, StringComparison.Ordinal)); if (null != workerInfo) { // Tell the worker object to stop this.traceSource.WriteInfo( this.logSourceId, "Stopping ETL producer worker object for application type {0} ...", applicationType); workerInfo.ProducerWorker.Dispose(); workerInfo.ProducerWorker = null; workerInfo.EtlProducers.Remove(this); if (0 == workerInfo.EtlProducers.Count) { // No one else is using the worker object. No need to // restart it. this.traceSource.WriteInfo( this.logSourceId, "No other ETL producer is using the ETL producer worker object for application type {0}, so no need to restart it.", applicationType); ProducerWorkers.Remove(workerInfo); } else { // Restart the worker. Arbitrarily choose one of the remaining // producers for supplying settings. this.traceSource.WriteInfo( this.logSourceId, "Restarting the ETL producer worker object for application type {0} because other ETL producers are using it.", applicationType); EtlProducer producer = workerInfo.EtlProducers[0]; EtlProducerWorker.EtlProducerWorkerParameters newWorkerParam = new EtlProducerWorker.EtlProducerWorkerParameters() { TraceSource = producer.traceSource, IsReadingFromApplicationManifest = !producer.etlProducerSettings.ProcessingWinFabEtlFiles, ApplicationType = applicationType, LogDirectory = producer.logDirectory, ProducerInstanceId = applicationType, EtlProducers = workerInfo.EtlProducers, LatestSettings = producer.etlProducerSettings }; try { EtlProducerWorker newWorker = new EtlProducerWorker( newWorkerParam, this.diskSpaceManager, this.traceFileEventReaderFactory); workerInfo.ProducerWorker = newWorker; } catch (InvalidOperationException) { this.traceSource.WriteError( this.logSourceId, "Failed to restart the ETL producer worker object for application type {0}.", applicationType); } } } } } else { if (null != this.producerWorker) { this.producerWorker.Dispose(); } } GC.SuppressFinalize(this); }