private void Dispose(bool isDisposing = true) { if (isDisposing) { lock (SyncRoot) { if (this.isDisposing) { return; } this.isDisposing = true; } GC.SuppressFinalize(this); } var disposed = false; void InternalDispose() { if (disposed) { return; // bail-out } disposed = true; AsyncCancellationTokenSource?.Cancel(); WebViewInitialized = null; BeforeNavigate = null; BeforeResourceLoad = null; Navigated = null; LoadFailed = null; DownloadProgressChanged = null; DownloadCompleted = null; DownloadCancelled = null; JavascriptContextCreated = null; TitleChanged = null; UnhandledAsyncException = null; JavascriptContextReleased = null; foreach (var disposable in disposables.Concat(JsExecutors?.Values)) { disposable?.Dispose(); } Disposed?.Invoke(); } if (JavascriptPendingCalls?.CurrentCount > 1) { // avoid dead-lock, wait for all pending calls to finish Task.Run(() => { JavascriptPendingCalls?.Signal(); // remove dummy entry JavascriptPendingCalls?.Wait(); InternalDispose(); }); return; } InternalDispose(); }
private void InnerDispose() { lock (SyncRoot) { if (isDisposing) { return; } isDisposing = true; } var disposed = false; void InternalDispose() { if (disposed) { return; // bail-out } disposed = true; AsyncCancellationTokenSource?.Cancel(); chromium.JavascriptContextCreated -= OnJavascriptContextCreated; chromium.JavascriptContextReleased -= OnJavascriptContextReleased; WebViewInitialized = null; BeforeNavigate = null; BeforeResourceLoad = null; Navigated = null; LoadFailed = null; DownloadProgressChanged = null; DownloadCompleted = null; DownloadCancelled = null; JavascriptContextCreated = null; TitleChanged = null; UnhandledAsyncException = null; JavascriptContextReleased = null; // dispose the js executors before the browser to prevent (the browser) from throwing cancellation exceptions DisposeJavascriptExecutors(); foreach (var disposable in disposables) { disposable?.Dispose(); } Disposed?.Invoke(); } if (JavascriptPendingCalls?.CurrentCount > 1) { // avoid dead-lock, wait for all pending calls to finish Task.Run(() => { JavascriptPendingCalls?.Signal(); // remove dummy entry JavascriptPendingCalls?.Wait(); InternalDispose(); }); return; } InternalDispose(); }