public void Start() { try { while (true) { string?outLine = ReadLine(stdoutHandle); string?errLine = ReadLine(stderrHandle); if (outLine != null) { NewOutLine?.Invoke(this, outLine); } if (errLine != null) { NewErrLine?.Invoke(this, errLine); } Thread.Sleep(500); } } catch (Exception ex) { ReadException?.Invoke(this, ex); } }
private async Task <ProtoMessage> Read() { try { var lengthArray = new byte[sizeof(int)]; var readBytes = 0; do { var count = lengthArray.Length - readBytes; readBytes += await _sslStream.ReadAsync(lengthArray, readBytes, count).ConfigureAwait(false); }while (readBytes < lengthArray.Length); Array.Reverse(lengthArray); var length = BitConverter.ToInt32(lengthArray, 0); if (length <= 0) { return(null); } var data = new byte[length]; readBytes = 0; do { var count = data.Length - readBytes; readBytes += await _sslStream.ReadAsync(data, readBytes, count).ConfigureAwait(false); }while (readBytes < length); return(ProtoMessage.Parser.ParseFrom(data)); } catch (Exception ex) { var readException = new ReadException(ex); OnError(readException); } return(null); }