以下的代码为new Process() 调用cmd命令,并将结果异步回显到Form的例子:
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using System.Xml;
namespace CmdCallbackShow
{
// 1.定义委托
public delegate void DelReadStdOutput(string result);
public delegate void DelReadErrOutput(string result);
public partial class MainWindow : Window
{
// 2.定义委托事件
public event DelReadStdOutput ReadStdOutput;
public event DelReadErrOutput ReadErrOutput;
public Form1()
{
InitializeComponent();
Init();
}
private void Init()
{
//3.将相应函数注册到委托事件中
ReadStdOutput += new DelReadStdOutput(ReadStdOutputAction);
ReadErrOutput += new DelReadErrOutput(ReadErrOutputAction);
}
private void button1_Click(