我创建一个网络诊断应用程序,并尝试将PathPing命令添加到它那里需要一个ADRESS从一个文本框的路径来ping当我按下一个按钮,但应用程序冻结当我按下按钮,输出窗口中不显示任何内容。C#的pathping过程冻结
private void btn_PingPath_Click(object sender, EventArgs e)
{
ProcessStartInfo PathPingStartInfo = new ProcessStartInfo();
PathPingStartInfo.FileName = "CMD.EXE";
PathPingStartInfo.UseShellExecute = false;
PathPingStartInfo.CreateNoWindow = true;
PathPingStartInfo.RedirectStandardOutput = true;
PathPingStartInfo.RedirectStandardInput = true;
PathPingStartInfo.RedirectStandardError = true;
PathPingStartInfo.StandardOutputEncoding = Encoding.GetEncoding(850);
Process PathPing = new Process();
PathPing.StartInfo = PathPingStartInfo;
PathPing.Start();
PathPing.StandardInput.WriteLine("PATHPING " + txt_PingPath.Text);
while (PathPing.StandardOutput.Peek() > -1)
{
txt_Output.Text = PathPing.StandardOutput.ReadLine();
}
while (PathPing.StandardError.Peek() > -1)
{
txt_Output.Text = PathPing.StandardError.ReadLine();
}
//txt_Output.Text = PathPing.StandardOutput.ReadToEnd();
PathPing.WaitForExit();
}
编辑
我发现从另一个问题while loop
,但它并没有帮助。在输出文本窗口中我仍然没有输出,应用程序仍然冻结。
预计这种'PathPing.WaitForExit();'不要在你的代码的最后一行..看起来像你的逻辑是关闭 – MethodMan
@MethodMan你能解释为什么它看起来像我的逻辑是关闭? – user5825579