internal void Cleanup() { if (Application.Current != null) { IBrowserCallbackServices browserCallbackServices = Application.Current.BrowserCallbackServices; if (browserCallbackServices != null) { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(this.ReleaseBrowserCallback), browserCallbackServices); } } this.ServiceProvider = null; this.ClearRootBrowserWindow(); if (this._storageRoot != null && this._storageRoot.Value != null) { this._storageRoot.Value.Close(); } if (this._document.Value is PackageDocument) { PreloadedPackages.RemovePackage(PackUriHelper.GetPackageUri(PackUriHelper.Create(this.Uri))); ((PackageDocument)this._document.Value).Dispose(); this._document.Value = null; } if (this._mimeType.Value == MimeType.Document) { DocumentManager.CleanUp(); } if (this._packageStream.Value != null) { this._packageStream.Value.Close(); } if (this._unmanagedStream.Value != null) { Marshal.ReleaseComObject(this._unmanagedStream.Value); this._unmanagedStream = new SecurityCriticalData <object>(null); } }
internal void Cleanup() { if (Application.Current != null) { IBrowserCallbackServices bcs = Application.Current.BrowserCallbackServices; if (bcs != null) { Debug.Assert(!Application.IsApplicationObjectShuttingDown); // Marshal.ReleaseComObject(bcs) has to be called so that the refcount of the // native objects goes to zero for clean shutdown. But it should not be called // right away, because there may still be DispatcherOperations in the queue // that will attempt to use IBCS, especially during downloading/activation. // Last, it can't be called with prioroty lower than Normal, because that's // the priority of Applicatoin.ShudownCallback(), which shuts down the // Dispatcher. Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new DispatcherOperationCallback(ReleaseBrowserCallback), bcs); } } ServiceProvider = null; ClearRootBrowserWindow(); if (_storageRoot != null && _storageRoot.Value != null) { _storageRoot.Value.Close(); } // Due to the dependecies the following objects have to be released // in the following order: _document, DocumentManager, // _packageStream, _unmanagedStream. if (_document.Value is PackageDocument) { // We are about to close the package ad remove it from the Preloaded Packages Store. // Let's make sure that the data structures are consistent. The package that we hold is // actually in the store under the URI that we think it should be using Debug.Assert(((PackageDocument)_document.Value).Package == PreloadedPackages.GetPackage(PackUriHelper.GetPackageUri(PackUriHelper.Create(Uri)))); // We need to remove the Package from the PreloadedPackage storage, // so that potential future requests would fail in a way of returning a null (resource not found) // rather then return a Package or stream that is already Closed PreloadedPackages.RemovePackage(PackUriHelper.GetPackageUri(PackUriHelper.Create(Uri))); ((PackageDocument)_document.Value).Dispose(); _document.Value = null; } if (_mimeType.Value == MimeType.Document) { DocumentManager.CleanUp(); } if (_packageStream.Value != null) { _packageStream.Value.Close(); } if (_unmanagedStream.Value != null) { Marshal.ReleaseComObject(_unmanagedStream.Value); _unmanagedStream = new SecurityCriticalData <object>(null); } }