consoletest.exe
Code:using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { int i; for (i = 0; i < 10000; i++) Console.Out.WriteLine(i.ToString()); } } }
windows project
The question isCode:private void button1_Click(object sender, EventArgs e) { System.Windows.Forms.Application.DoEvents(); System.Diagnostics.Process proc = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo(); pi.FileName = "C:\\consoletest.exe"; pi.Arguments = "C:\\mailbox"; pi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; pi.RedirectStandardOutput = true; pi.UseShellExecute = false; proc.StartInfo = pi; proc.Start(); System.IO.StreamReader myOutput = proc.StandardOutput; proc.WaitForExit(); if (proc.HasExited) { string output = myOutput.ReadToEnd(); textBox1.Text = output; } }
How do I run the console program in background and update its output in real time to the textbox?
The windows program should also continue accepting other Events while the console process is being executed.




Reply With Quote