问题
Problem:
in my code, I set a timeout of a ping to 100ms
new Ping().Send(item._deviceIP, 100, new byte[1])
which pings correctly and replies correctly, but the IPStatus.TimeExceeded is "faulty" and reports a success after the RTT is > 100ms
What should happen:
when recieving a pingreply, if the IPStatus is a:
TimeExceeded (>100ms), _devicePing should have a color set to Red
Success(<=100ms), _devicePing should have a color set to green
any other, appropriate color is set.
What happens:
Any ping reply which is a reply report success even with a RTT >100ms
class device
{
public IPAddress _deviceIP;
public string _deviceMAC;
public string _deviceName;
public PingReply _devicePing ;
public Color _deviceStatus = Color.White;
public int _timeout_Count = 0;
public Color deviceStatus
{
get { return _deviceStatus; }
set { _deviceStatus = value; }
}
Main Program Code
List<device> _alive = new List<device>();
foreach (device item in _clients)
{
PingReply _client_reply = new Ping().Send(item._deviceIP, 100, new byte[1]);
item._devicePing = _client_reply; (item object accepts a PingReply)
IPStatus _client_status = _client_reply.Status;
switch (_client_status)
{
case IPStatus.TimeExceeded:
{
item.deviceStatus = Color.Red;
}
break;
//rest of code
回答1:
You will need to check the status of the PingReply in all cases. When specifying very small numbers for timeout, the Ping reply can be received even if timeout milliseconds have elapsed.
And now you ask the difficult question - what is a very small number 500ms, 250ms, 100ms 10ms, ??? Glad you asked .. see this article for no answwer to that question. https://msdn.microsoft.com/en-us/library/ms144954%28v=vs.110%29.aspx
来源:https://stackoverflow.com/questions/34238629/c-sharp-ping-exceeds-timeout-but-reports-success