Example #1
0
        /// <summary>
        /// Send a command to debugger.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        public async Task SendRequestAsync(DebuggerCommand command, CancellationToken cancellationToken = new CancellationToken()) {
            cancellationToken.ThrowIfCancellationRequested();

            try {
                TaskCompletionSource<JObject> promise = _messages.GetOrAdd(command.Id, i => new TaskCompletionSource<JObject>());
                _connection.SendMessage(command.ToString());
                cancellationToken.ThrowIfCancellationRequested();

                JObject response = await promise.Task.ConfigureAwait(false);
                cancellationToken.ThrowIfCancellationRequested();

                command.ProcessResponse(response);
            } finally {
                TaskCompletionSource<JObject> promise;
                _messages.TryRemove(command.Id, out promise);
            }
        }
 private async Task<bool> TrySendRequestAsync(DebuggerCommand command, CancellationToken cancellationToken = new CancellationToken()) {
     try {
         await _client.SendRequestAsync(command, cancellationToken).ConfigureAwait(false);
         return true;
     } catch (DebuggerCommandException ex) {
         var evt = DebuggerOutput;
         if (evt != null) {
             evt(this, new OutputEventArgs(null, ex.Message + Environment.NewLine));
         }
         return false;
     }
 }