문제

I need to decide if timeout has occurred and save the entry into list array.

This is how I ping and add the round trip value to one list array:

static void Ping()
{
    Console.Write(Environment.NewLine + "Start the test? (y/n): ");

    if (Console.ReadLine().ToLower() == "y")
    {
        List<int> lag = new List<int>();

        Console.WriteLine();

        for (int server = 1; server <= 139; server++)
        {
            string url = "world" + server.ToString() + ".runescape.com";

            Console.WriteLine("Checking world " + server + "...");

            Ping ping = new Ping();
            PingReply reply = ping.Send(url);

            lag.Add(int.Parse(reply.RoundtripTime.ToString()));
        }

    // ... More Code Here ...

    }
}

How to do this?

도움이 되었습니까?

해결책

See the Status property

reply.Status

it returns an IPStatus which should have the according status.

다른 팁

It seems that you need to use the value in PingReply.Status to determine whether a timeout occurred or not. MSDN documentation states:

If the value of Status is not Success, you should not use the values returned by the RoundtripTime, Options or Buffer properties. The RoundtripTime and Buffer properties will return zero, and the Options property will return null.

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.pingreply.status.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top