public void ReceiveMessage(InboundMessage message) { CancellationToken cancellationToken = new CancellationToken(false); Task<ResponseMessage> task = this.ReceiveMessage(message, cancellationToken, 0); task.ContinueWith(ContinuationAction, cancellationToken); task.Start(); }
private Task<ResponseMessage> ReceiveMessage(InboundMessage message, CancellationToken cancellationToken, int position) { if (cancellationToken.IsCancellationRequested || position == this.messageFilters.Count) { return new Task<ResponseMessage>(() => new ResponseMessage("Message not handled.")); } Task<ResponseMessage> response = this.messageFilters[position].Handle(message, cancellationToken, () => this.ReceiveMessage(message, cancellationToken, ++position)); return response; }