/// <inheritdoc /> public Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default) { var tcs = new TaskCompletionSource <BrowserResult>(); var window = _windowFactory(); var webView = new WebViewCompatible(); window.Content = webView; webView.NavigationStarting += (sender, e) => { if (e.Uri.AbsoluteUri.StartsWith(options.EndUrl)) { tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.Success, Response = e.Uri.ToString() }); if (_shouldCloseWindow) { window.Close(); } else { window.Content = null; } } }; window.Closing += (sender, e) => { webView.Dispose(); if (!tcs.Task.IsCompleted) { tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.UserCancel }); } }; window.Show(); webView.Navigate(options.StartUrl); return(tcs.Task); }
private void DisposeBrowser(object sender, FormClosingEventArgs e) { webBrowser.Dispose(); }