共用方式為


PingReply.RoundtripTime 屬性

定義

取得用於傳送網際網路控制訊息通訊協定 (ICMP) 回應要求及接收對應的 ICMP 回應回覆訊息的毫秒數。

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

屬性值

Int64,指定來回時間 (以毫秒為單位)。

範例

下列程式代碼範例會同步傳送ICMP回應要求,並顯示此屬性傳回的緩衝區大小。

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

備註

如果 Echo 要求失敗,則會 RoundtripTime 將時間回報為 0,這也是要求成功時的有效值。 您必須檢查 , Status 以判斷是否應該忽略這個屬性傳回的值。

適用於