This documentation is archived and is not being maintained.

PingReply.RoundtripTime Property

Gets the number of milliseconds taken to send an Internet Control Message Protocol (ICMP) echo request and receive the corresponding ICMP echo reply message.

Namespace:  System.Net.NetworkInformation
Assembly:  System (in System.dll)

public long RoundtripTime { get; }

Property Value

Type: System.Int64
An Int64 that specifies the round trip time, in milliseconds.

If the Echo request fails, the RoundtripTime time is reported as 0, which is also a valid value when the request succeeds. You must check the Status to determine whether the value returned by this property should be ignored.

The following code example sends an ICMP echo request synchronously and displays the size of the buffer returned by this property.

public static void ComplexPing ()
{
    Ping pingSender = new Ping ();

    // Create a buffer of 32 bytes of data to be transmitted.
    string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    byte[] buffer = Encoding.ASCII.GetBytes (data);

    // Wait 10 seconds for a reply. 
    int timeout = 10000;

    // Set options for transmission: 
    // The data can go through 64 gateways or routers 
    // before it is destroyed, and the data packet 
    // cannot be fragmented.
    PingOptions options = new PingOptions (64, true);

    // Send the request.
    PingReply reply = pingSender.Send ("www.contoso.com", timeout, buffer, options);

    if (reply.Status == IPStatus.Success)
    {
        Console.WriteLine ("Address: {0}", reply.Address.ToString ());
        Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
        Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
        Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
        Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
    }
    else
    {
        Console.WriteLine (reply.Status);
    }
}
void ComplexPing ()
{
    Ping* pingSender = new Ping ();

    // Create a buffer of 32 bytes of data to be transmitted.
    String* data = S"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    Byte buffer[] = Encoding::ASCII->GetBytes (data);

    // Wait 10 seconds for a reply.
    int timeout = 10000;

    // Set options for transmission:
    // The data can go through 64 gateways or routers
    // before it is destroyed, and the data packet
    // cannot be fragmented.
    PingOptions* options = new PingOptions (64, true);

    // Send the request.
    PingReply* reply = pingSender->Send (S"www.contoso.com", buffer, timeout, options);

    if (reply->Status == IPStatus::Success)
    {
        Console::WriteLine (S"Address: {0}", reply->Address->ToString ());
        Console::WriteLine (S"RoundTrip time: {0}", __box(reply->RoundTripTime));
        Console::WriteLine (S"Time to live: {0}", __box(reply->Options->Ttl));
        Console::WriteLine (S"Don't fragment: {0}", __box(reply->Options->DontFragment));
        Console::WriteLine (S"Buffer size: {0}", __box(reply->Buffer->Length));
    }
    else
    {
        Console::WriteLine (reply->Status);
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: