internal Task <bool> SendMessage(string message, PipeMessageType pipeMessageType) { if (!IsConnected) { throw new Exception("Pipe is not connected"); } var transmit = new PipeTransmit(message, pipeMessageType); _transmits.TryAdd(transmit.Id, transmit); SendTransmit(transmit); return(transmit.Tcs.Task); }
void SendTransmit(PipeTransmit transmit) { Task.Run(async() => { try { await WriteToPipe(transmit.Packet); await transmit.Tcs.Task.TimeoutAfter(transmit.Timeout); } catch (Exception ex) { _logger.Error($"Send transmit error: '{ex.Message}, packet: {transmit.Packet}'"); if (_transmits.TryRemove(transmit.Id, out var removed)) { removed.Tcs.SetException(ex); } } }); }