예제 #1
0
        private async Task SendAsync(Message message, CancellationToken ct)
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            _log.Request(message.ToString(), _rLoopDepth);

            try {
                await _transport.SendAsync(message, ct);
            } catch (MessageTransportException ex) when(ct.IsCancellationRequested)
            {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            } catch (MessageTransportException ex) {
                throw new RHostDisconnectedException(ex.Message, ex);
            }
        }
예제 #2
0
        private async Task SendAsync(JToken token, CancellationToken ct)
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            var json = JsonConvert.SerializeObject(token);

            _log.Request(json, _rLoopDepth);

            try {
                await _transport.SendAsync(json, ct);
            } catch (MessageTransportException ex) when(ct.IsCancellationRequested)
            {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            }
        }