Ping Ping Ping Ping Class

定義

可以讓應用程式判斷是否能透過網路存取遠端電腦。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. 目前狀態和 proxy、 網路位址轉譯 (NAT) 設備或防火牆的設定可以防止Ping無法成功。The 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.

這個類別會提供類似 Ping.exe 命令列工具的功能。This class provides functionality similar to the Ping.exe command line tool. SendSendAsync方法從該電腦將網際網路控制訊息通訊協定 (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. (請參閱Send或是SendAsync多載會採用buffer參數。)(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或是SendAsync多載會採用options參數。)(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. (請參閱TtlSend或是SendAsync多載會採用options參數。)(See Ttl and the Send or SendAsync overloads that take an options parameter.)

  • 必須在其中接收回覆的時間限制。The time limit within which the reply must be received. (請參閱Send或是SendAsync多載會採用timeout參數。(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. 您必須新增PingCompletedEventHandler再呼叫事件的委派SendAsyncYou must add a PingCompletedEventHandler delegate to the event before calling SendAsync. 委派的方法會接收PingCompletedEventArgs物件,其中包含PingReply物件,描述結果的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. 呼叫Send雖然SendAsync呼叫是進行中或呼叫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() Ping() Ping()

初始化 Ping 類別的新執行個體。Initializes a new instance of the Ping class.

方法

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

釋放 Ping 物件所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。Releases the unmanaged resources used by the Ping object, and optionally disposes of the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnPingCompleted(PingCompletedEventArgs) OnPingCompleted(PingCompletedEventArgs) OnPingCompleted(PingCompletedEventArgs) OnPingCompleted(PingCompletedEventArgs)

引發 PingCompleted 事件。Raises the PingCompleted event.

Send(IPAddress) Send(IPAddress) Send(IPAddress) Send(IPAddress)

嘗試將網際網路控制訊息通訊協定 (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) Send(IPAddress, Int32) Send(IPAddress, Int32) Send(IPAddress, Int32)

嘗試將網際網路控制訊息通訊協定 (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[]) Send(IPAddress, Int32, Byte[]) Send(IPAddress, Int32, Byte[]) Send(IPAddress, Int32, Byte[])

嘗試將網際網路控制訊息通訊協定 (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) Send(IPAddress, Int32, Byte[], PingOptions) Send(IPAddress, Int32, Byte[], PingOptions) Send(IPAddress, Int32, Byte[], PingOptions)

嘗試將網際網路控制訊息通訊協定 (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) Send(String) Send(String) Send(String)

嘗試將網際網路控制訊息通訊協定 (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) Send(String, Int32) Send(String, Int32) Send(String, Int32)

嘗試將網際網路控制訊息通訊協定 (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[]) Send(String, Int32, Byte[]) Send(String, Int32, Byte[]) Send(String, Int32, Byte[])

嘗試將網際網路控制訊息通訊協定 (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) Send(String, Int32, Byte[], PingOptions) Send(String, Int32, Byte[], PingOptions) Send(String, Int32, Byte[], PingOptions)

嘗試將網際網路控制訊息通訊協定 (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) SendAsync(IPAddress, Int32, Byte[], Object) SendAsync(IPAddress, Int32, Byte[], Object) SendAsync(IPAddress, Int32, Byte[], Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (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) SendAsync(IPAddress, Int32, Byte[], PingOptions, Object) SendAsync(IPAddress, Int32, Byte[], PingOptions, Object) SendAsync(IPAddress, Int32, Byte[], PingOptions, Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (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) SendAsync(IPAddress, Int32, Object) SendAsync(IPAddress, Int32, Object) SendAsync(IPAddress, Int32, Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,傳送給具有指定之 IPAddress 的電腦,並從該電腦接收對應的 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) SendAsync(IPAddress, Object) SendAsync(IPAddress, Object) SendAsync(IPAddress, Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,傳送給具有指定之 IPAddress 的電腦,並從該電腦接收對應的 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) SendAsync(String, Int32, Byte[], Object) SendAsync(String, Int32, Byte[], Object) SendAsync(String, Int32, Byte[], Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (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) SendAsync(String, Int32, Byte[], PingOptions, Object) SendAsync(String, Int32, Byte[], PingOptions, Object) SendAsync(String, Int32, Byte[], PingOptions, Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (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) SendAsync(String, Int32, Object) SendAsync(String, Int32, Object) SendAsync(String, Int32, Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (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) SendAsync(String, Object) SendAsync(String, Object) SendAsync(String, Object)

嘗試以非同步方式將網際網路控制訊息通訊協定 (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() SendAsyncCancel() SendAsyncCancel() SendAsyncCancel()

取消傳送網際網路控制訊息通訊協定 (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) SendPingAsync(IPAddress) SendPingAsync(IPAddress) SendPingAsync(IPAddress)

以非同步作業的方式,將網際網路控制訊息通訊協定 (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) SendPingAsync(IPAddress, Int32) SendPingAsync(IPAddress, Int32) SendPingAsync(IPAddress, Int32)

以非同步作業的方式,將網際網路控制訊息通訊協定 (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[]) SendPingAsync(IPAddress, Int32, Byte[]) SendPingAsync(IPAddress, Int32, Byte[]) SendPingAsync(IPAddress, Int32, Byte[])

以非同步作業的方式,將網際網路控制訊息通訊協定 (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) SendPingAsync(IPAddress, Int32, Byte[], PingOptions) SendPingAsync(IPAddress, Int32, Byte[], PingOptions) SendPingAsync(IPAddress, Int32, Byte[], PingOptions)

使用指定資料緩衝區傳送網際網路控制訊息通訊協定 (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) SendPingAsync(String) SendPingAsync(String) SendPingAsync(String)

以非同步作業的方式,將網際網路控制訊息通訊協定 (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) SendPingAsync(String, Int32) SendPingAsync(String, Int32) SendPingAsync(String, Int32)

以非同步作業的方式,將網際網路控制訊息通訊協定 (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[]) SendPingAsync(String, Int32, Byte[]) SendPingAsync(String, Int32, Byte[]) SendPingAsync(String, Int32, Byte[])

以非同步作業的方式,將網際網路控制訊息通訊協定 (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) SendPingAsync(String, Int32, Byte[], PingOptions) SendPingAsync(String, Int32, Byte[], PingOptions) SendPingAsync(String, Int32, Byte[], PingOptions)

以非同步作業的方式,將網際網路控制訊息通訊協定 (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() ToString() ToString() ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(Inherited from Component)

事件

Disposed Disposed Disposed Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
PingCompleted PingCompleted PingCompleted PingCompleted

當傳送網際網路控制訊息通訊協定 (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() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

釋放 Ping 類別執行個體使用的所有資源。Releases all resources used by instances of the Ping class.

屬性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(Inherited from Component)
DesignMode DesignMode DesignMode DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
Site Site Site Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)

適用於

另請參閱