SendPingAsync回复返回11050

时间:2016-07-06 17:56:21

标签: c# asynchronous ping

我尝试使用SendPingAsync创建一个简单的ping应用程序。但是,pingReply.Status.ToString()返回奇怪的数字" 11050"连接断开时。它将返回不成功的消息,如" TimedOut"或" DestinationHostUnreachable",但过了几秒钟。这意味着什么?

这是我的代码:

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

编辑:这是我的应用程序截图:

Right after disconnect

After 10-15 "11050" message

1 个答案:

答案 0 :(得分:0)

伙伴 此代码:11050表示一般失败

请求失败的原因不明。

有关详细信息,请参阅知识库文章325487,&#34;如何解决网络连接问题&#34; (http://go.microsoft.com/fwlink/?linkid=3052&kbid=325487)。