private async Task <REvaluationResult> EvaluateAsyncWorker(string expression, REvaluationKind kind, CancellationToken cancellationToken) { await TaskUtilities.SwitchToBackgroundThread(); var request = await EvaluationRequest.SendAsync(this, expression, kind, cancellationToken); return(await request.Task); }
public async Task <REvaluationResult> EvaluateAsync(string expression, REvaluationKind kind, CancellationToken cancellationToken) { if (_runTask == null) { throw new InvalidOperationException("Host was not started"); } using (CancellationTokenUtilities.Link(ref cancellationToken, _cts.Token)) { try { await TaskUtilities.SwitchToBackgroundThread(); var request = await EvaluationRequest.SendAsync(this, expression, kind, cancellationToken); return(await request.Task); } catch (OperationCanceledException ex) when(_cts.IsCancellationRequested) { throw new RHostDisconnectedException(Resources.Error_RHostIsStopped, ex); } } }