private async Task <bool> RunWithProgressAsync(Func <CancellationToken, Task> asyncAction, ProgressDialog progressDialog, CancellationToken token) { var hideProgress = ShowProgressDialog(progressDialog); using (var cancellationDisposable = new CancellationDisposable()) using (token.Register(cancellationDisposable.Dispose)) using (progressDialog.Token.Register(cancellationDisposable.Dispose)) { try { await asyncAction(cancellationDisposable.Token); } catch (OperationCanceledException) when(progressDialog.Token.IsCancellationRequested) { return(true); } catch (OperationCanceledException) { token.ThrowIfCancellationRequested(); throw; } finally { hideProgress(); } } return(false); }
public async void HandleReloadJavaScript() { DispatcherHelpers.AssertOnDispatcher(); HideRedboxDialog(); HideDevOptionsDialog(); var message = !IsRemoteDebuggingEnabled ? "Fetching JavaScript bundle." : "Connecting to remote debugger."; var progressDialog = new ProgressDialog("Please wait...", message); #if WINDOWS_UWP var dialogOperation = progressDialog.ShowAsync(); Action cancel = dialogOperation.Cancel; #else progressDialog.ShowDialog(); Action cancel = progressDialog.Hide; #endif if (IsRemoteDebuggingEnabled) { await ReloadJavaScriptInProxyMode(cancel, progressDialog.Token).ConfigureAwait(false); } else if (_jsBundleFile == null) { await ReloadJavaScriptFromServerAsync(cancel, progressDialog.Token).ConfigureAwait(false); } else { await ReloadJavaScriptFromFileAsync(progressDialog.Token); cancel(); } }