private async void ProcessCommands() { while (!this.cancellationTokenSource.IsCancellationRequested) { try { IReceivedCommand command = await this.client.ReadAsync(this.cancellationTokenSource.Token); if (this.inflightCommands.ContainsKey(command.CommandId)) { this.inflightCommands[command.CommandId].TrySetResult(command); } if (this.commandHandlers.ContainsKey(command.CommandId)) { var handler = this.commandHandlers[command.CommandId]; handler.ForEach(c => c.Update(command)); } } catch (TaskCanceledException) { } } }
public void TrySetResult(IReceivedCommand command) { task.TrySetResult(command); }