Question

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?

Was it helpful?

Solution

See the Status property

reply.Status

it returns an IPStatus which should have the according status.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top