Visual|window
Pipeline technology is generally implemented using the window API, I recently tried to use C # to implement the Windows pipeline technology, found that C # itself convenient process threading mechanism to make the work is very simple, and record, recommended to everyone.
First, we can get the output interface by setting the process class, and the code is as follows:
Process proc = new Process();
proc .StartInfo.FileName = strScript;
proc .StartInfo.WorkingDirectory = strDirectory;
proc .StartInfo.CreateNoWindow = true;
proc .StartInfo.UseShellExecute = false;
proc .StartInfo.RedirectStandardOutput = true;
proc .Start();
Then set the string that the thread reads output sequentially:
eventOutput = new AutoResetEvent(false);
AutoResetEvent[] events = new AutoResetEvent[1];
events[0] = m_eventOutput;
m_threadOutput = new Thread( new ThreadStart( DisplayOutput ) );
m_threadOutput.Start();
WaitHandle.WaitAll( events );
The thread functions are as follows:
private void DisplayOutput()
{
while ( m_procScript != null && !m_procScript.HasExited )
{
string strLine = null;
while ( ( strLine = m_procScript.StandardOutput.ReadLine() ) != null)
{
m_txtOutput.AppendText( strLine + "\r\n" );
m_txtOutput.SelectionStart = m_txtOutput.Text.Length;
m_txtOutput.ScrollToCaret();
}
Thread.Sleep( 100 );
}
m_eventOutput.Set();
}
Note here that the following statement is used to make the textbox display always the most recently added, and appendtext instead of + = because = = causes the entire textbox to be echoing so that the entire display area flashes
m_txtOutput.AppendText( strLine + "\r\n" );
m_txtOutput.SelectionStart = m_txtOutput.Text.Length;
m_txtOutput.ScrollToCaret();
In order not to block the main thread, you can put the whole process on a different line Chengri.