Default ping timeout

sanchop22 picture sanchop22 · Jun 18, 2013 · Viewed 14.2k times · Source

What is the default time of ping? I use the code below to send ping to tcp devices. When does IPStatus fall to timeout?

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

Thank you.

Answer

Marc Gravell picture Marc Gravell · Jun 18, 2013

From MSDN here and here

The method waits five seconds for an ICMP echo reply message. If it does not receive a reply in that time, the method returns and the Status property is set to TimedOut.

And if we check in reflector, indeed we see:

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