当我使用Windows Ping远程系统时,它说没有回复,但是当我用c#ping时,它表示成功.Windows正确,设备未连接.为什么我的代码能够在Windows不成功时成功ping?
这是我的代码:
Ping p1 = new Ping();
PingReply PR = p1.Send("192.168.2.18");
// check when the ping is not success
while (!PR.Status.ToString().Equals("Success"))
{
Console.WriteLine(PR.Status.ToString());
PR = p1.Send("192.168.2.18");
}
// check after the ping is n success
while (PR.Status.ToString().Equals("Success"))
{
Console.WriteLine(PR.Status.ToString());
PR = p1.Send("192.168.2.18");
}
Run Code Online (Sandbox Code Playgroud) 我在C#中异步读取一个进程的输出时遇到问题.我在这个网站上发现了一些其他类似的问题,但它们对我没有帮助.这是我做的:
它工作正常,但启动过程的输出写了一些%我想得到的百分比(),但我不能,因为我的代码逐行读取,百分比没有显示.
例:
%0,%1...%100
Finished.
Run Code Online (Sandbox Code Playgroud)
我的输出:
%0
Finished.
Run Code Online (Sandbox Code Playgroud)
这是我的程序的当前代码:
StringBuilder sBuilder = new StringBuilder();
static void proc_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
sBuilder.AppendLine(e.Data);
}
static void CommandExecutor()
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = /*path of the program*/,
Arguments = /*arguments*/,
CreateNoWindow = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
RedirectStandardOutput = true
}
};
process.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
}
Run Code Online (Sandbox Code Playgroud)