Ping 类

定义

允许应用程序确定是否可通过网络访问远程计算机。Allows an application to determine whether a remote computer is accessible over the network.

public ref class Ping : System::ComponentModel::Component, IDisposable
public class Ping : System.ComponentModel.Component, IDisposable
type Ping = class
    inherit Component
    interface IDisposable
Public Class Ping
Inherits Component
Implements IDisposable
继承
实现

示例

下面的代码示例演示如何以同步方式使用 Ping 类。The following code example demonstrates using the Ping class synchronously.

#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::NetworkInformation;
using namespace System::Text;

// args[1] can be an IPaddress or host name.
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   
   Ping ^ pingSender = gcnew Ping;
   PingOptions ^ options = gcnew PingOptions;
   
   // Use the default Ttl value which is 128,
   // but change the fragmentation behavior.
   options->DontFragment = true;
   
   // Create a buffer of 32 bytes of data to be transmitted.
   String^ data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
   array<Byte>^buffer = Encoding::ASCII->GetBytes( data );
   int timeout = 120;
   PingReply ^ reply = pingSender->Send( args[ 1 ], 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 );
   }

   
}

using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        // args[0] can be an IPaddress or host name.
        public static void Main (string[] args)
        {
            Ping pingSender = new Ping ();
            PingOptions options = new PingOptions ();

            // Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes (data);
            int timeout = 120;
            PingReply reply = pingSender.Send (args[0], 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);
            }
        }
    }
}

下面的代码示例演示如何以异步方式使用 Ping 类。The following code example demonstrates using the Ping class asynchronously.

#using <System.dll>

using namespace System;
using namespace System::Text;
using namespace System::Net;
using namespace System::Net::NetworkInformation;
using namespace System::ComponentModel;
using namespace System::Threading;
void PingCompletedCallback( Object^ sender, PingCompletedEventArgs^ e );
void DisplayReply( PingReply^ reply );
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   if ( args->Length == 1 )
      throw gcnew ArgumentException( "Ping needs a host or IP Address." );

   String^ who = args[ 1 ];
   AutoResetEvent^ waiter = gcnew AutoResetEvent( false );
   
   Ping ^ pingSender = gcnew Ping;
   
   // When the PingCompleted event is raised,
   // the PingCompletedCallback method is called.
   pingSender->PingCompleted += gcnew PingCompletedEventHandler( PingCompletedCallback );
   
   // Create a buffer of 32 bytes of data to be transmitted.
   String^ data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
   array<Byte>^buffer = Encoding::ASCII->GetBytes( data );
   
   // Wait 12 seconds for a reply.
   int timeout = 12000;
   
   // 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 = gcnew PingOptions( 64,true );
   Console::WriteLine( "Time to live: {0}", options->Ttl );
   Console::WriteLine( "Don't fragment: {0}", options->DontFragment );
   
   // Send the ping asynchronously.
   // Use the waiter as the user token.
   // When the callback completes, it can wake up this thread.
   pingSender->SendAsync( who, timeout, buffer, options, waiter );
   
   // Prevent this example application from ending.
   // A real application should do something useful
   // when possible.
   waiter->WaitOne();
   Console::WriteLine( "Ping example completed." );
}


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


void DisplayReply( PingReply ^ reply )
{
   if ( reply == nullptr )
      return;

   Console::WriteLine( "ping status: {0}", reply->Status );
   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 );
   }
}

using System;
using System.Text;
using System.Net;
using System.Net.NetworkInformation;
using System.ComponentModel;
using System.Threading;

namespace Examples.System.Net.NetworkInformation.PingTest
{
    public class PingExample
    {
        public static void Main (string[] args)
        {
            if (args.Length == 0)
                throw new ArgumentException ("Ping needs a host or IP Address.");

            string who = args[0];
            AutoResetEvent waiter = new AutoResetEvent (false);

            Ping pingSender = new Ping ();

            // When the PingCompleted event is raised,
            // the PingCompletedCallback method is called.
            pingSender.PingCompleted += new PingCompletedEventHandler (PingCompletedCallback);

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes (data);

            // Wait 12 seconds for a reply.
            int timeout = 12000;

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

            Console.WriteLine ("Time to live: {0}", options.Ttl);
            Console.WriteLine ("Don't fragment: {0}", options.DontFragment);

            // Send the ping asynchronously.
            // Use the waiter as the user token.
            // When the callback completes, it can wake up this thread.
            pingSender.SendAsync(who, timeout, buffer, options, waiter);

            // Prevent this example application from ending.
            // A real application should do something useful
            // when possible.
            waiter.WaitOne ();
            Console.WriteLine ("Ping example completed.");
        }

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

        public static void DisplayReply (PingReply reply)
        {
            if (reply == null)
                return;

            Console.WriteLine ("ping status: {0}", reply.Status);
            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);
            }
        }
    }
}

注解

应用程序使用 Ping 类来检测远程计算机是否可访问。Applications use the Ping class to detect whether a remote computer is reachable.

网络拓扑可以确定 Ping 是否可以成功连接到远程主机。Network topology can determine whether Ping can successfully contact a remote host. 代理、网络地址转换(NAT)设备或防火墙的存在和配置可能会阻止 PingThe presence and configuration of proxies, network address translation (NAT) equipment, or firewalls can prevent Ping from succeeding. 成功的 Ping 仅指示可在网络上访问远程主机;不保证远程主机上存在较高级别的服务(如 Web 服务器)。A successful Ping indicates only that the remote host can be reached on the network; the presence of higher level services (such as a Web server) on the remote host is not guaranteed.

此类提供类似于命令行工具的功能。This class provides functionality similar to the Ping.exe command line tool. SendSendAsync 方法向远程计算机发送 Internet 控制消息协议(ICMP)回送请求消息,并等待来自该计算机的 ICMP 回送答复消息。The Send and SendAsync methods send an Internet Control Message Protocol (ICMP) echo request message to a remote computer and waits for an ICMP echo reply message from that computer. 有关 ICMP 消息的详细说明,请参阅 RFC 792, https://www.ietf.org提供。For a detailed description of ICMP messages, see RFC 792, available at https://www.ietf.org.

以下类型与 Ping 类结合使用,如下所述。The following types are used with the Ping class and are described in detail below.

类型名称Type name 说明Description
IPStatus 定义用于描述 ICMP 回送请求消息的结果的状态代码。Defines status codes that describe the outcome of an ICMP echo request message.
PingOptions 允许您配置或检索设置,这些设置控制请求数据包可以被转发的次数(Ttl)以及是否可以分段(DontFragment)。Allows you to configure or retrieve the settings that control how many times the request packet can be forwarded (Ttl), and whether it can be fragmented (DontFragment ).
PingReply 包含 ICMP 回送请求的结果。Contains the results of an ICMP echo request.
PingException 如果发生不可恢复的错误,则引发。Thrown if an unrecoverable error occurs.
PingCompletedEventArgs 包含与 PingCompleted 事件关联的数据,这些事件在 SendAsync 调用完成或取消时引发。Contains the data associated with PingCompleted events, which are raised when a SendAsync call completes or is canceled.
PingCompletedEventHandler 委托,它提供在 SendAsync 调用完成或取消时调用的回调方法。The delegate that provides the callback method invoked when a SendAsync call completes or is canceled.

SendSendAsync 方法返回 PingReply 对象中的答复。The Send and SendAsync methods return the reply in a PingReply object. PingReply.Status 属性返回一个 IPStatus 值,该值指示请求的结果。The PingReply.Status property returns an IPStatus value to indicate the outcome of the request.

发送请求时,必须指定远程计算机。When sending the request, you must specify the remote computer. 可以通过提供主机名字符串、字符串格式的 IP 地址或 IPAddress 对象来执行此操作。You can do this by providing a host name string, an IP address in string format, or an IPAddress object.

你还可以指定以下任何类型的信息:You can also specify any of the following types of information:

  • 要伴随请求的数据。Data to accompany the request. 通过指定 buffer,你可以了解特定大小的数据包传送到远程主机和网络路径的最大传输单元所需的时间量。Specifying buffer allows you to learn the amount of time required for a packet of a particular size to travel to and from the remote host and the maximum transmission unit of the network path. (请参阅采用 buffer 参数的 SendSendAsync 重载。)(See the Send or SendAsync overloads that take a buffer parameter.)

  • ICMP Echo 数据包是否可以在传输过程中进行分段。Whether the ICMP Echo packet can be fragmented in transit. (请参阅 DontFragment 属性和 Send 或采用 options 参数的 SendAsync 重载。)(See the DontFragment property and the Send or SendAsync overloads that take an options parameter.)

  • 路由节点(如路由器或网关)在到达目标计算机或被丢弃之前可以转发数据包的次数。How many times routing nodes, such as routers or gateways, can forward the packet before it either reaches the destination computer or is discarded. (请参阅 Ttl 和使用 options 参数的 SendSendAsync 重载。)(See Ttl and the Send or SendAsync overloads that take an options parameter.)

  • 必须在此时间内接收回复的时间限制。The time limit within which the reply must be received. (请参阅采用 timeout 参数的 SendSendAsync 重载。(See the Send or SendAsync overloads that take a timeout parameter.

Ping 类提供用于发送请求的同步和异步方法。The Ping class offers both synchronous and asynchronous methods for sending the request. 如果你的应用程序应在等待答复时阻塞,请使用 Send 方法;这些方法是同步的。If your application should block while waiting for a reply, use the Send methods; these methods are synchronous. 如果你的应用程序不应阻止,请使用异步 SendAsync 方法。If your application should not block, use the asynchronous SendAsync methods. SendAsync 的调用会在其自己的线程中执行,该线程会自动从线程池分配。A call to SendAsync executes in its own thread that is automatically allocated from the thread pool. 异步操作完成后,它会引发 PingCompleted 事件。When the asynchronous operation completes, it raises the PingCompleted event. 应用程序使用 PingCompletedEventHandler 委托来指定为 PingCompleted 事件调用的方法。Applications use a PingCompletedEventHandler delegate to specify the method that is called for PingCompleted events. 在调用 SendAsync之前,必须将 PingCompletedEventHandler 委托添加到事件。You must add a PingCompletedEventHandler delegate to the event before calling SendAsync. 委托的方法接收一个包含 PingReply 对象的 PingCompletedEventArgs 对象,该对象描述 SendAsync 调用的结果。The delegate's method receives a PingCompletedEventArgs object that contains a PingReply object that describes the result of the SendAsync call.

不能使用 Ping 类的同一个实例来生成多个同时 ICMP 回显请求。You cannot use the same instance of the Ping class to generate multiple simultaneous ICMP Echo requests. SendAsync 调用正在进行时调用 Send,或在之前的所有调用都完成之前调用 SendAsync 多次导致了 InvalidOperationExceptionCalling Send while a SendAsync call is in progress or calling SendAsync multiple times before all previous calls have completed causes an InvalidOperationException.

构造函数

Ping()

初始化 Ping 类的新实例。Initializes a new instance of the Ping class.

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
Site

获取或设置 ISiteComponentGets or sets the ISite of the Component.

(继承自 Component)

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()
Dispose(Boolean)

释放由 Ping 对象使用的非托管资源,并可根据需要释放托管资源。Releases the unmanaged resources used by the Ping object, and optionally disposes of the managed resources.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnPingCompleted(PingCompletedEventArgs)

引发 PingCompleted 事件。Raises the PingCompleted event.

Send(IPAddress)

尝试将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送答复消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer.

Send(IPAddress, Int32)

尝试将包含指定数据缓冲区的 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送应答消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer. 使用此方法可以为操作指定一个超时值。This method allows you to specify a time-out value for the operation.

Send(IPAddress, Int32, Byte[])

尝试将包含指定数据缓冲区的 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送应答消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

Send(IPAddress, Int32, Byte[], PingOptions)

尝试将包含指定数据缓冲区的 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定 IPAddress 的计算机,并接收来自该计算机的相应 ICMP 回送答复消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress and receive a corresponding ICMP echo reply message from that computer. 此重载允许您指定操作的超时值,并控制 ICMP 回显消息数据包的碎片和生存时间值。This overload allows you to specify a time-out value for the operation and control fragmentation and Time-to-Live values for the ICMP echo message packet.

Send(String)

尝试向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message to the specified computer, and receive a corresponding ICMP echo reply message from that computer.

Send(String, Int32)

尝试向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message to the specified computer, and receive a corresponding ICMP echo reply message from that computer. 使用此方法可以为操作指定一个超时值。This method allows you to specify a time-out value for the operation.

Send(String, Int32, Byte[])

尝试用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,然后从该计算机接收对应的 ICMP 回显回复消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

Send(String, Int32, Byte[], PingOptions)

尝试用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,然后从该计算机接收对应的 ICMP 回显回复消息。Attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer. 此重载允许您指定操作的超时值,并控制 ICMP 数据包的碎片和生存时间值。This overload allows you to specify a time-out value for the operation and control fragmentation and Time-to-Live values for the ICMP packet.

SendAsync(IPAddress, Int32, Byte[], Object)

尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回显回复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

SendAsync(IPAddress, Int32, Byte[], PingOptions, Object)

尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回显回复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer. 此重载允许您指定操作的超时值,并控制 ICMP 回显消息数据包的碎片和生存时间值。This overload allows you to specify a time-out value for the operation and control fragmentation and Time-to-Live values for the ICMP echo message packet.

SendAsync(IPAddress, Int32, Object)

尝试以异步方式向指定 IPAddress 的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

SendAsync(IPAddress, Object)

尝试以异步方式向指定 IPAddress 的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message to the computer that has the specified IPAddress, and receive a corresponding ICMP echo reply message from that computer.

SendAsync(String, Int32, Byte[], Object)

尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,并从该计算机接收对应的 ICMP 回显回复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

SendAsync(String, Int32, Byte[], PingOptions, Object)

尝试用指定的数据缓冲区以异步方式将 Internet 控制消息协议 (ICMP) 回显消息发送到指定计算机,并从该计算机接收对应的 ICMP 回显回复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer. 此重载允许您指定操作的超时值,并控制 ICMP 数据包的碎片和生存时间值。This overload allows you to specify a time-out value for the operation and control fragmentation and Time-to-Live values for the ICMP packet.

SendAsync(String, Int32, Object)

尝试以异步方式向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message to the specified computer, and receive a corresponding ICMP echo reply message from that computer. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

SendAsync(String, Object)

尝试以异步方式向指定的计算机发送 Internet 控制消息协议 (ICMP) 回送消息,并从该计算机接收相应的 ICMP 回送答复消息。Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message to the specified computer, and receive a corresponding ICMP echo reply message from that computer.

SendAsyncCancel()

取消所有挂起的发送 Internet 控制消息协议 (ICMP) 回送消息并接收相应 ICMP 回送答复消息的异步请求。Cancels all pending asynchronous requests to send an Internet Control Message Protocol (ICMP) echo message and receives a corresponding ICMP echo reply message.

SendPingAsync(IPAddress)

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receives a corresponding ICMP echo reply message from that computer as an asynchronous operation.

SendPingAsync(IPAddress, Int32)

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receives a corresponding ICMP echo reply message from that computer as an asynchronous operation. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

SendPingAsync(IPAddress, Int32, Byte[])

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receives a corresponding ICMP echo reply message from that computer as an asynchronous operation. 此重载将允许您为操作指定超时值并指定用于发送和接收的缓冲区。This overload allows you to specify a time-out value for the operation and a buffer to use for send and receive.

SendPingAsync(IPAddress, Int32, Byte[], PingOptions)

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到具有指定的 IPAddress 的计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified IPAddress, and receives a corresponding ICMP echo reply message from that computer as an asynchronous operation. 利用此重载,您可以指定操作的超时值和用于进行发送和接收的缓冲区,并可以控制 ICMP 回送消息数据包的碎片和生存时间值。This overload allows you to specify a time-out value for the operation, a buffer to use for send and receive, and control fragmentation and Time-to-Live values for the ICMP echo message packet.

SendPingAsync(String)

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer as an asynchronous operation.

SendPingAsync(String, Int32)

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer as an asynchronous operation. 此重载使您可以为操作指定一个超时值。This overload allows you to specify a time-out value for the operation.

SendPingAsync(String, Int32, Byte[])

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer as an asynchronous operation. 此重载将允许您为操作指定超时值并指定用于发送和接收的缓冲区。This overload allows you to specify a time-out value for the operation and a buffer to use for send and receive.

SendPingAsync(String, Int32, Byte[], PingOptions)

使用指定的数据缓冲区将 Internet 控制消息协议 (ICMP) 回送消息发送到指定计算机,并从该计算机接收对应的 ICMP 回送答复消息以作为异步操作。Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, and receive a corresponding ICMP echo reply message from that computer as an asynchronous operation. 利用此重载,您可以指定操作的超时值和用于进行发送和接收的缓冲区,并可以控制 ICMP 回送消息数据包的碎片和生存时间值。This overload allows you to specify a time-out value for the operation, a buffer to use for send and receive, and control fragmentation and Time-to-Live values for the ICMP echo message packet.

ToString()

返回包含 String 的名称的 Component(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
PingCompleted

当发送 Internet 控制消息协议 (ICMP) 回送消息并接收相应 ICMP 回送答复消息的异步操作完成或被取消时发生。Occurs when an asynchronous operation to send an Internet Control Message Protocol (ICMP) echo message and receive the corresponding ICMP echo reply message completes or is canceled.

显式接口实现

IDisposable.Dispose()

释放由 Ping 类的实例使用的所有资源。Releases all resources used by instances of the Ping class.

适用于

另请参阅