private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (CancellationToken.IsCancellationRequested && !Process.HasExited) { Stop(); return; } if (!string.IsNullOrEmpty(e.Data)) { Debug(e.Data); ErrorBuilder.AppendLine(e.Data); OnError?.Invoke(e.Data); } }
public void Start() { if (_process == null) { throw new Exception("Can't reuse disposed job"); } _process.OutputDataReceived += (_, e) => { // e.Data is null to signal end of stream if (e.Data != null) { _standardOutput.Enqueue(e.Data); OnStandardOutput?.Invoke(e.Data); OutputBuilder.AppendLine(e.Data); } }; _process.ErrorDataReceived += (_, e) => { // e.Data is null to signal end of stream if (e.Data != null) { _standardError.Enqueue(e.Data); OnStandardError?.Invoke(e.Data); ErrorBuilder.AppendLine(e.Data); } }; StartTimeUtc = DateTime.UtcNow; _process.Start(); _process.BeginOutputReadLine(); _process.BeginErrorReadLine(); }