PingCompletedEventArgs.Reply 屬性
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得物件,包含描述嘗試傳送網際網路控制訊息通訊協定 (ICMP) 回應要求訊息,以及接收對應的 ICMP 回應回覆訊息的資料。
public:
property System::Net::NetworkInformation::PingReply ^ Reply { System::Net::NetworkInformation::PingReply ^ get(); };
C#
public System.Net.NetworkInformation.PingReply? Reply { get; }
C#
public System.Net.NetworkInformation.PingReply Reply { get; }
member this.Reply : System.Net.NetworkInformation.PingReply
Public ReadOnly Property Reply As PingReply
PingReply 物件,描述 ICMP 回應要求的結果。
下列程式代碼範例會實作用來回應 PingCompleted 事件的方法。 如需完整的範例,請參閱 PingCompletedEventArgs 類別概觀。
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.
(dynamic_cast<AutoResetEvent^>(e->UserState))->Set();
}
// If an error occurred, display the exception to the user.
if ( e->Error != nullptr )
{
Console::WriteLine( "Ping failed:" );
Console::WriteLine( e->Error->ToString() );
// Let the main thread resume.
(dynamic_cast<AutoResetEvent^>(e->UserState))->Set();
}
PingReply ^ reply = e->Reply;
DisplayReply( reply );
// Let the main thread resume.
(dynamic_cast<AutoResetEvent^>(e->UserState))->Set();
}
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,您就不應該使用 、 Options和 Buffer 屬性所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 |