PingReply.RoundtripTime Propriedade

Definição

Obtém o número de milissegundos necessários para enviar um pedido de eco do Internet Control Message Protocol (ICMP) e receber a correspondente mensagem de resposta ICMP.

public:
 property long RoundtripTime { long get(); };
public long RoundtripTime { get; }
member this.RoundtripTime : int64
Public ReadOnly Property RoundtripTime As Long

Valor de Propriedade

E Int64 que especifica o tempo de ida e volta, em milissegundos.

Exemplos

O exemplo de código seguinte envia um pedido de eco ICMP de forma síncrona e mostra o tamanho do buffer devolvido por esta propriedade.

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

Observações

Se o pedido Echo falhar, o RoundtripTime tempo é reportado como 0, que também é um valor válido quando o pedido tem sucesso. Deve verificar para Status determinar se o valor devolvido por esta propriedade deve ser ignorado.

Aplica-se a