public void StartProcess() { if (this.process != null) { throw new Exception("Process already started"); } try { this.process = this.CreateUnderlyingProcess(true); } catch (Exception ex) { SimpleFileLogger.Instance.LogError("Unable to start the underying process", ex); if (this.process != null) { this.process.Exited -= OnProcess_Exited; this.process.Dispose(); this.process = null; } throw new Exception("Unable to start the process"); } if (this.process != null) { this.process.PriorityClass = ProcessPriorityClass.BelowNormal; Object streamSyncer = new Object(); this.outputStreamObserver = this.BeginReadStream(this.process.StandardOutput, streamSyncer, "Unable to read output stream"); this.errorStreamObserver = this.BeginReadStream(this.process.StandardError, streamSyncer, "Unable to read error stream"); } }
private StreamObserver BeginReadStream(StreamReader argStream, Object messageSyncer, string argErrorMessage) { StreamObserver tmpResult; try { tmpResult = new StreamObserver(argStream, messageSyncer); tmpResult.MessageReceived += OnStreamObserver_MessageReceived; tmpResult.BeginObservation(); } catch (Exception ex) { SimpleFileLogger.Instance.LogError(ex); throw new Exception(argErrorMessage, ex); } return(tmpResult); }
private void OnStreamObserver_MessageReceived(StreamObserver argSender, string argData) { this.OnMessageReceived(new ProcessMessage(argData, DateTime.UtcNow, argSender == this.outputStreamObserver)); }