/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (!this._isDisposed) { ExportProvider rootProvider = null; AggregateExportProvider aggregatingExportProvider = null; ComposablePartExportProvider partExportProvider = null; CatalogExportProvider catalogExportProvider = null; ImportEngine importEngine = null; lock (this._lock) { if (!this._isDisposed) { rootProvider = this._rootProvider; this._rootProvider = null; aggregatingExportProvider = this._aggregatingExportProvider; this._aggregatingExportProvider = null; partExportProvider = this._partExportProvider; this._partExportProvider = null; catalogExportProvider = this._catalogExportProvider; this._catalogExportProvider = null; importEngine = this._importEngine; this._importEngine = null; this._isDisposed = true; } } if (rootProvider != null) { rootProvider.ExportsChanged -= this.OnExportsChangedInternal; rootProvider.ExportsChanging -= this.OnExportsChangingInternal; } if (aggregatingExportProvider != null) { aggregatingExportProvider.Dispose(); } if (catalogExportProvider != null) { catalogExportProvider.Dispose(); } if (partExportProvider != null) { partExportProvider.Dispose(); } if (importEngine != null) { importEngine.Dispose(); } } } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (!_isDisposed) { //Note: We do not dispose _lock on dispose because DisposePart needs it to check isDisposed state // to eliminate race conditions between it and Dispose INotifyComposablePartCatalogChanged catalogToUnsubscribeFrom = null; HashSet <IDisposable> partsToDispose = null; ImportEngine importEngine = null; ExportProvider sourceProvider = null; AggregateExportProvider aggregateExportProvider = null; try { using (_lock.LockStateForWrite()) { if (!_isDisposed) { catalogToUnsubscribeFrom = _catalog as INotifyComposablePartCatalogChanged; _catalog = null; aggregateExportProvider = _innerExportProvider as AggregateExportProvider; _innerExportProvider = null; sourceProvider = _sourceProvider; _sourceProvider = null; importEngine = _importEngine; _importEngine = null; partsToDispose = _partsToDispose; _gcRoots = null; _isDisposed = true; } } } finally { if (catalogToUnsubscribeFrom != null) { catalogToUnsubscribeFrom.Changing -= OnCatalogChanging; } if (aggregateExportProvider != null) { aggregateExportProvider.Dispose(); } if (sourceProvider != null) { sourceProvider.ExportsChanging -= OnExportsChangingInternal; } if (importEngine != null) { importEngine.Dispose(); } if (partsToDispose != null) { foreach (var part in partsToDispose) { part.Dispose(); } } } } } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (disposing) { if (!this._isDisposed) { bool disposeLock = false; INotifyComposablePartCatalogChanged catalogToUnsubscribeFrom = null; HashSet <IDisposable> partsToDispose = null; ImportEngine importEngine = null; ExportProvider sourceProvider = null; AggregateExportProvider aggregateExportProvider = null; try { using (this._lock.LockStateForWrite()) { if (!this._isDisposed) { catalogToUnsubscribeFrom = this._catalog as INotifyComposablePartCatalogChanged; this._catalog = null; aggregateExportProvider = this._innerExportProvider as AggregateExportProvider; this._innerExportProvider = null; sourceProvider = this._sourceProvider; this._sourceProvider = null; importEngine = this._importEngine; this._importEngine = null; partsToDispose = this._partsToDispose; this._gcRoots = null; disposeLock = true; this._isDisposed = true; } } } finally { if (catalogToUnsubscribeFrom != null) { catalogToUnsubscribeFrom.Changing -= this.OnCatalogChanging; } if (aggregateExportProvider != null) { aggregateExportProvider.Dispose(); } if (sourceProvider != null) { sourceProvider.ExportsChanging -= this.OnExportsChangingInternal; } if (importEngine != null) { importEngine.Dispose(); } if (partsToDispose != null) { foreach (var part in partsToDispose) { part.Dispose(); } } if (disposeLock) { this._lock.Dispose(); } } } } }