Tutorials to .com

Tutorials to .com » Dotnet » Application » [Original] C # to achieve Window Pipeline Technology

[Original] C # to achieve Window Pipeline Technology

Print View , by: iSee ,Total views: 34 ,Word Count: 360 ,Date: Wed, 26 Aug 2009 Time: 10:05 PM

Made prior to use Window API to implement a pipeline technology articles, then use c # to achieve the same effect, found that C++ # itself is a mechanism to facilitate the process of thread makes the job extremely easy to hand, look at records.

First of all, we can by setting the Process class, access to the output interface, 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 ();

And then set the thread continuously reads the output string:

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);

Thread function is 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 ();
)

Here we must note that the following statement to add a TextBox always shows the latest, but AppendText instead of using the + =, because + = will cause the TextBox's Echo makes the whole display area flicker

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 entire process can be a another thread where a



.Net Application Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.