/// <summary> /// Stops all workers, allowing them to finish handling the current message (for up to 1 minute) before exiting /// </summary> public void Dispose() { // this Dispose may be called when the Disposed event is raised - therefore, we need // to guard against recursively entering this method if (_disposing) { return; } try { _disposing = true; _busLifetimeEvents.RaiseBusDisposing(); // signal to all the workers that they must stop lock (_workers) { _workers.ForEach(StopWorker); } SetNumberOfWorkers(0); _busLifetimeEvents.RaiseWorkersStopped(); Disposed(); } finally { _disposing = false; _busLifetimeEvents.RaiseBusDisposed(); } }
/// <summary> /// Stops all workers, allowing them to finish handling the current message (for up to 1 minute) before exiting /// </summary> public void Dispose() { // this Dispose may be called when the Disposed event is raised - therefore, we need // to guard against recursively entering this method if (_disposing) { return; } if (_disposed) { return; } try { _disposing = true; _busLifetimeEvents.RaiseBusDisposing(); // signal to all the workers that they must stop if (_workers.IsValueCreated) { _workers.Value.Dispose(); } _busLifetimeEvents.RaiseWorkersStopped(); Disposed(); } finally { _disposing = false; _disposed = true; _busLifetimeEvents.RaiseBusDisposed(); _log.Info("Bus {busName} stopped", _busName); } }