部分示例代码:
1 public delegate void DelReadStdOutput(string result);
2         public delegate void DelReadErrOutput(string result);
3         public event DelReadStdOutput ReadStdOutput;
4         public event DelReadErrOutput ReadErrOutput;
5 /// <summary>
6         /// 注册事件
7         /// </summary>
8         private void Init()
9         {
10             ReadStdOutput += new DelReadStdOutput(ReadStdOutputAction);
11             ReadErrOutput += new DelReadErrOutput(ReadErrOutputAction);
12
13         }
14 //----------------------部分实现代码==================
15 using (p = new Process())
16                 {
17
18                     //pause --  停止
19                     p.StartInfo.FileName = fileName;
20
21                     p.StartInfo.UseShellExecute = false;
22                     p.StartInfo.CreateNoWindow = true;
23
24                     p.StartInfo.RedirectStandardError = true;
25                     p.StartInfo.RedirectStandardInput = true;
26                     p.StartInfo.RedirectStandardOutput = true;
27                     p.EnableRaisingEvents = true;
28                     p.Exited += new EventHandler(p_Exited);
29                     p.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
30                     p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
31
32                     p.Start();
33                     //读取输出:
34                     p.BeginErrorReadLine();
35                     p.BeginOutputReadLine();
36                     p.WaitForExit();
37                 }
38
39
40 void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
41         {
42             this.lab_tips.Text = "开始读取数据...读取时间可能有点长,请耐心等待!";
43             if (e.Data != null)
44             {
45                 this.Invoke(ReadStdOutput, new object[] { e.Data });
46             }
47 }
48 // 读取进程信息:
49 public void ReadStdOutputAction(string s)
50         {
51
52             if (num > 1)
53             {
54                 budiler.AppendLine(s);
55             }
56             this.textBox1.Text = budiler.ToString();
57             num++;
58         }
  暂时到这儿了。