PingCompletedEventArgs.Reply 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取包含数据的对象,该数据描述发送 Internet 控制消息协议 (ICMP) 回送请求消息并接受相应的 ICMP 回送答复消息的尝试。
public:
property System::Net::NetworkInformation::PingReply ^ Reply { System::Net::NetworkInformation::PingReply ^ get(); };
public System.Net.NetworkInformation.PingReply? Reply { get; }
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();
}
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,则不应使用 、 RoundtripTimeOptions和 Buffer 属性返回的值。
RoundtripTime和 Buffer 属性将返回零,属性Options将返回 null
。