public void CancelLinked() { var cts = new CancellationTokenSource(); var token = cts.Token; using (_disposeToken.Link(ref token)) { _disposeToken.TryMarkDisposed(); } token.IsCancellationRequested.Should().BeTrue(); cts.Token.IsCancellationRequested.Should().BeFalse(); }
public async Task <bool> PromptYesNoAsync(string text, CancellationToken cancellationToken) { using (_disposeToken.Link(ref cancellationToken)) { var result = await _workflow.Services.ShowMessageAsync(text, MessageButtons.YesNo, cancellationToken); return(result == MessageButtons.Yes); } }
public async Task TestBrokerConnectionAsync(string name, BrokerConnectionInfo connectionInfo, CancellationToken cancellationToken = default(CancellationToken)) { using (_disposeToken.Link(ref cancellationToken)) { await TaskUtilities.SwitchToBackgroundThread(); // Create random name to avoid collision with actual broker client name = name + Guid.NewGuid().ToString("N"); var brokerClient = CreateBrokerClient(name, connectionInfo, cancellationToken); if (brokerClient == null) { throw new ArgumentException(nameof(connectionInfo)); } using (brokerClient) { await TestBrokerConnectionWithRHost(brokerClient, cancellationToken); } } }
public async Task RefreshEnvironmentsAsync(CancellationToken cancellationToken = default(CancellationToken)) { using (_disposeToken.Link(ref cancellationToken)) { var session = _rSession; await TaskUtilities.SwitchToBackgroundThread(); var envs = new List <REnvironment>(); bool success = false; try { var traceback = (await session.TracebackAsync(cancellationToken: cancellationToken)) .Skip(1) // skip global - it's in the search path already .Select(frame => new REnvironment(frame)) .Reverse(); if (traceback.Any()) { envs.AddRange(traceback); envs.Add(null); } var searchPath = (await session.EvaluateAsync <string[]>("as.list(search())", REvaluationKind.BaseEnv, cancellationToken)) .Except(_hiddenEnvironments) .Select(name => new REnvironment(name)); envs.AddRange(searchPath); success = true; } catch (RException) { } catch (OperationCanceledException) { } await _mainThread.SwitchToAsync(cancellationToken); var oldSelection = _selectedEnvironment; _environments.ReplaceWith(success ? envs : _errorEnvironments); IREnvironment newSelection = null; if (oldSelection != null) { newSelection = _environments?.FirstOrDefault(env => env?.Name == oldSelection.Name); } SelectedEnvironment = newSelection ?? _environments.FirstOrDefault(); } }