/// <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) { // Don't reference event listeners any longer: AddressChanged = null; BrowserInitialized = null; ConsoleMessage = null; FrameLoadEnd = null; FrameLoadStart = null; LoadError = null; LoadingStateChanged = null; Paint = null; StatusMessage = null; TitleChanged = null; Cef.RemoveDisposable(this); if (disposing) { browser = null; IsBrowserInitialized = false; if (managedCefBrowserAdapter != null) { if (!managedCefBrowserAdapter.IsDisposed) { managedCefBrowserAdapter.Dispose(); } managedCefBrowserAdapter = null; } } // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter // otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version, // we do it here for consistency) this.SetHandlersToNull(); }
protected virtual void Dispose(bool isdisposing) { //Check if alreadty disposed if (Interlocked.Increment(ref disposeCount) == 1) { // No longer reference event listeners: ConsoleMessage = null; FrameLoadStart = null; FrameLoadEnd = null; LoadError = null; LoadingStateChanged = null; Rendering = null; // No longer reference handlers: this.SetHandlersToNull(); if (isdisposing) { if (BrowserSettings != null) { BrowserSettings.Dispose(); BrowserSettings = null; } PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler); // Release internal event listeners: Loaded -= OnLoaded; GotKeyboardFocus -= OnGotKeyboardFocus; LostKeyboardFocus -= OnLostKeyboardFocus; // Release internal event listeners for Drag Drop events: DragEnter -= OnDragEnter; DragOver -= OnDragOver; DragLeave -= OnDragLeave; Drop -= OnDrop; IsVisibleChanged -= OnIsVisibleChanged; if (tooltipTimer != null) { tooltipTimer.Tick -= OnTooltipTimerTick; } if (CleanupElement != null) { CleanupElement.Unloaded -= OnCleanupElementUnloaded; } if (managedCefBrowserAdapter != null) { managedCefBrowserAdapter.Dispose(); managedCefBrowserAdapter = null; } foreach (var disposable in disposables) { disposable.Dispose(); } disposables.Clear(); UiThreadRunAsync(() => WebBrowser = null); } Cef.RemoveDisposable(this); RemoveSourceHook(); } }