默认ping超时时间

13

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);
    }
}

谢谢您。


你测量了什么? - GolezTrol
1个回答

25

来自MSDN 这里这里

该方法等待五秒钟以获取ICMP回显应答消息。如果在此期间未接收到回复,则该方法将返回并设置Status属性为TimedOut。

如果我们在反编译器中查看,确实会看到:

public PingReply Send(string hostNameOrAddress)
{
    return this.Send(hostNameOrAddress, 5000, this.DefaultSendBuffer, null);
}

有没有可能覆盖掉5秒的值? - Harold_Finch
@Harold_Finch 目前为止我不知道。 - Marc Gravell
"AFAIK" 是什么意思? - Harold_Finch
据我所知,@Harold_Finch。 - Marc Gravell
1
在最新的.Net版本中,有一个重载函数可以指定超时时间。链接 - itsho

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接