public AsynchronousAggregateStreamReader(StreamBuffer outputStreamBuffer, StreamBuffer errorStreamBuffer)
 {
     _outputStreamBuffer = outputStreamBuffer;
     _errorStreamBuffer = errorStreamBuffer;
 }
Пример #2
0
        private static void WireUpTheOutputOfTheReplProcessToTheTextBox(TextBox replTextBox, Process replProcess, Entity<ReplState> replEntity)
        {
            var standardOutputStream = new StreamBuffer();
            var standardErrorStream = new StreamBuffer();
            var textboxWriter = new TextBoxWriter(replTextBox, replEntity);

            var processStreamReader = new AsynchronousAggregateStreamReader(standardOutputStream, standardErrorStream);
            processStreamReader.DataReceived += textboxWriter.WriteToTextBox;

            var outputReaderThread = new Thread(processStreamReader.StartReading);
            var outputBufferStreamThread = new Thread(() => standardOutputStream.ReadStream(replProcess.StandardOutput.BaseStream));
            var errorBufferStreamThread = new Thread(() => standardOutputStream.ReadStream(replProcess.StandardError.BaseStream));

            replTextBox.Loaded +=
                (o, e) =>
                {
                    if (outputReaderThread.IsAlive) return;
                    replProcess.Start();
                    replProcess.StandardInput.AutoFlush = true;
                    outputBufferStreamThread.Start();
                    errorBufferStreamThread.Start();
                    outputReaderThread.Start();
                };

            replProcess.Exited +=
                (o, e) =>
                {
                    outputBufferStreamThread.Abort();
                    errorBufferStreamThread.Abort();
                    outputReaderThread.Abort();
                };
        }