C# Класс Twinspire.ProcessIoManager

Class that manages the reading of the output produced by a given 'Process' and reports the output via events. Both standard error (stderr) and standard output (stdout) are managed and reported. The stdout and stderr monitoring and reading are each performed by separate background threads. Each thread blocks on a Read() method, waiting for text in the stream being monitored to become available. Note the Process.RedirectStandardOutput must be set to true in order to read standard output from the process, and the Process.RedirectStandardError must be set to true to read standard error.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
ProcessIoManager ( Process process ) : System

Initializes a new instance of the ProcessIoManager class.

Does not automatically start listening for stdout/stderr. Call StartProcessOutputRead() to begin listening for process output.

StartProcessOutputRead ( ) : void

Starts the background threads reading any output produced (standard output, standard error) that is produces by the running process.

StopMonitoringProcessOutput ( ) : void

Stops both the standard input and stardard error background reader threads (via the Abort() method)

WriteStdin ( string text ) : void

Writes the supplied text string to the standard input (stdin) of the running process

In order to be able to write to the Process, the StartInfo.RedirectStandardInput must be set to true.

Приватные методы

Метод Описание
CheckForValidProcess ( string errorMessageText, bool checkForHasExited ) : void

Checks for valid (non-null Process), and optionally check to see if the process has exited. Throws Exception if process is null, or if process has existed and checkForHasExited is true.

NotifyAndFlushBufferText ( StringBuilder textbuffer, bool isstdout ) : void

Invokes the OnStdoutTextRead (if isstdout==true)/ OnStderrTextRead events with the supplied streambuilder 'textbuffer', then clears textbuffer after event is invoked.

ReadStandardErrorThreadMethod ( ) : void

Method started in a background thread (stderrThread) to manage the reading and reporting of standard error text produced by the running process.

ReadStandardOutputThreadMethod ( ) : void

Method started in a background thread (stdoutThread) to manage the reading and reporting of standard output text produced by the running process.

ReadStream ( int firstCharRead, StreamReader streamReader, bool isstdout ) : void

Read characters from the supplied stream, and accumulate them in the 'streambuffer' variable until there are no more characters to read.

Time_Tick ( object sender, EventArgs e ) : void

Описание методов

ProcessIoManager() публичный Метод

Initializes a new instance of the ProcessIoManager class.
Does not automatically start listening for stdout/stderr. Call StartProcessOutputRead() to begin listening for process output.
public ProcessIoManager ( Process process ) : System
process System.Diagnostics.Process The process.
Результат System

StartProcessOutputRead() публичный Метод

Starts the background threads reading any output produced (standard output, standard error) that is produces by the running process.
public StartProcessOutputRead ( ) : void
Результат void

StopMonitoringProcessOutput() публичный Метод

Stops both the standard input and stardard error background reader threads (via the Abort() method)
public StopMonitoringProcessOutput ( ) : void
Результат void

WriteStdin() публичный Метод

Writes the supplied text string to the standard input (stdin) of the running process
In order to be able to write to the Process, the StartInfo.RedirectStandardInput must be set to true.
public WriteStdin ( string text ) : void
text string The text to write to running process input stream.
Результат void