我想使用SendPingAsync做一個簡單的ping應用程序。但是,當連接斷開連接時,pingReply.Status.ToString()返回奇怪的數字「11050」。它會返回不成功的消息,如「TimedOut」或「DestinationHostUnreachable」,但幾秒後。這是什麼意思?SendPingAsync回覆11050
這裏是我的代碼:
async Task ngeping(String host, CancellationToken ct)
{
Ping ping = new Ping();
IPAddress ipaddress;
PingReply pingReply = null;
long tripTime;
while (true)
{
if (ct.IsCancellationRequested) break;
tripTime = -1;
try
{
pingReply = await ping.SendPingAsync(host, 3000);
ipaddress = pingReply.Address;
if (pingReply.Status == IPStatus.Success)
{
tripTime = pingReply.RoundtripTime;
if(tripTime<300)
gaweRTF.insertLine(GaweRTF.HIGHLIGHT_GREEN, ipaddress.ToString() + " - " + tripTime + " ms");
else if (tripTime < 500)
gaweRTF.insertLine(GaweRTF.HIGHLIGHT_YELLOW, ipaddress.ToString() + " - " + tripTime + " ms");
else
gaweRTF.insertLine(GaweRTF.HIGHLIGHT_RED, ipaddress.ToString() + " - " + tripTime + " ms");
}
else
gaweRTF.insertLine(GaweRTF.HIGHLIGHT_RED, "not success: "+pingReply.Status.ToString());
}
catch
{
gaweRTF.insertLine(GaweRTF.HIGHLIGHT_RED, ERROR_MESSAGE);
}
rtb.Rtf = gaweRTF.finishRTF();
if (tripTime>=0 && tripTime<1000) await Task.Delay(1000 - (int) tripTime);
if (pingReply.Status != IPStatus.Success) await Task.Delay(1000);
}
}
編輯:這裏我的應用程序截圖:
你確定它是'11050'嗎?你確定它不是'110005'嗎? –
是的,我添加了屏幕截圖。 pingReply.Status.ToString()是11050.另外,如果消息「110005」,這是什麼意思? – ErinQvnm