0
我正在使用的是一个程序,它在命令提示符下运行命令并将结果输出到窗体中。但是,无论何时您启动该命令,它都会锁定窗体窗体,然后您无法再单击窗体上的任何内容。这是一个问题,因为我想添加一个停止按钮,请参阅下面的相应代码。在命令提示符运行时使用Windows窗体
private void Start_Click(object sender, EventArgs e)
{
var proc = new Process();
proc.StartInfo.Arguments = "/C robocopy " + "\"" + source.Text + "\" \"" + Destination.Text + "\" /E /ZB /W:1 /R:3 /MT /A-:SH";
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.EnableRaisingEvents = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
// see below for output handler
proc.ErrorDataReceived += proc_DataReceived;
proc.OutputDataReceived += proc_DataReceived;
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit();
}
工作完美;非常感谢你! – xjacksssss