private void InternalDispose() { AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoaded; DisposableWebViews.Remove(this); cancellationTokenSource.Cancel(); WebViewInitialized = null; BeforeNavigate = null; BeforeResourceLoad = null; Navigated = null; LoadFailed = null; DownloadProgressChanged = null; DownloadCompleted = null; DownloadCancelled = null; JavascriptContextCreated = null; TitleChanged = null; UnhandledAsyncException = null; RenderProcessCrashed = null; JavascriptContextReleased = null; jsExecutor.Dispose(); settings.Dispose(); chromium.Dispose(); cancellationTokenSource.Dispose(); Disposed?.Invoke(); }
public void Dispose() { if (isDisposing) { return; } isDisposing = true; GC.SuppressFinalize(this); var disposed = false; void InternalDispose() { if (disposed) { return; // bail-out } disposed = true; AppDomain.CurrentDomain.AssemblyLoad -= OnAssemblyLoaded; DisposableWebViews.Remove(this); cancellationTokenSource.Cancel(); WebViewInitialized = null; BeforeNavigate = null; BeforeResourceLoad = null; Navigated = null; LoadFailed = null; DownloadProgressChanged = null; DownloadCompleted = null; DownloadCancelled = null; JavascriptContextCreated = null; TitleChanged = null; UnhandledAsyncException = null; RenderProcessCrashed = null; JavascriptContextReleased = null; jsExecutor.Dispose(); settings.Dispose(); chromium.Dispose(); cancellationTokenSource.Dispose(); Disposed?.Invoke(); } // avoid dead-lock, wait for all pending calls to finish JavascriptCallFinished += () => { if (javascriptPendingCalls == 0) { Dispatcher.BeginInvoke((Action)InternalDispose); } }; if (javascriptPendingCalls > 0) { // JavascriptCallFinished event will trigger InternalDispose, // this check must come after registering event to avoid losing the event call return; } InternalDispose(); }