默认ping超时

san*_*p22 9 c# ping

ping的默认时间是多少?我使用下面的代码向tcp设备发送ping.IPStatus什么时候会超时?

private static void ApplyPing(Topology.Runtime rt)
{
    try
    {
        if (rt.TcpClient != null)
        {
            string ip = rt.Ip;
            if (new Ping().Send(ip).Status != IPStatus.Success)
            {
                Service.WriteEventLog(string.Format("{0} ping error.", ip), EventLogEntryType.Warning);
                rt.Disconnect();
            }
        }
    }
    catch (ArgumentNullException ex)
    { 

    }
    catch (Exception ex)
    {
        Service.WriteEventLog(ex, EventLogEntryType.Error);
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

Mar*_*ell 19

来自MSDN 这里这里

该方法等待五秒钟以获取ICMP回送回复消息.如果在该时间内没有收到回复,则该方法返回,并且Status属性设置为TimedOut.

如果我们检查反射器,确实我们看到:

public PingReply Send(string hostNameOrAddress)
{
    return this.Send(hostNameOrAddress, 5000, this.DefaultSendBuffer, null);
}
Run Code Online (Sandbox Code Playgroud)