PingCompletedEventArgs.Reply 屬性

定義

取得物件,包含描述嘗試傳送網際網路控制訊息通訊協定 (ICMP) 回應要求訊息,以及接收對應的 ICMP 回應回覆訊息的資料。

C#
public System.Net.NetworkInformation.PingReply? Reply { get; }
C#
public System.Net.NetworkInformation.PingReply Reply { get; }

屬性值

PingReply 物件,描述 ICMP 回應要求的結果。

範例

下列程式代碼範例會實作用來回應 PingCompleted 事件的方法。 如需完整的範例,請參閱 PingCompletedEventArgs 類別概觀。

C#
private static void PingCompletedCallback (object sender, PingCompletedEventArgs e)
{
    // If the operation was canceled, display a message to the user.
    if (e.Cancelled)
    {
        Console.WriteLine ("Ping canceled.");

        // Let the main thread resume.
        // UserToken is the AutoResetEvent object that the main thread
        // is waiting for.
        ((AutoResetEvent)e.UserState).Set ();
    }

    // If an error occurred, display the exception to the user.
    if (e.Error != null)
    {
        Console.WriteLine ("Ping failed:");
        Console.WriteLine (e.Error.ToString ());

        // Let the main thread resume.
        ((AutoResetEvent)e.UserState).Set();
    }

    PingReply reply = e.Reply;

    DisplayReply (reply);

    // Let the main thread resume.
    ((AutoResetEvent)e.UserState).Set();
}

備註

如果的值Status不是 Success,您就不應該使用 、 OptionsBuffer 屬性所RoundtripTime傳回的值。 RoundtripTime屬性 Buffer 會傳回零,而 Options 屬性會傳回 null

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1