Ping 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
可以讓應用程式判斷是否能透過網路存取遠端電腦。
public ref class Ping : System::ComponentModel::Component
public ref class Ping : IDisposable
public ref class Ping : System::ComponentModel::Component, IDisposable
public class Ping : System.ComponentModel.Component
public class Ping : IDisposable
public class Ping : System.ComponentModel.Component, IDisposable
type Ping = class
inherit Component
type Ping = class
interface IDisposable
type Ping = class
inherit Component
interface IDisposable
Public Class Ping
Inherits Component
Public Class Ping
Implements IDisposable
Public Class Ping
Inherits Component
Implements IDisposable
- 繼承
- 繼承
-
Ping
- 實作
範例
下列程式碼範例示範如何同步使用 Ping 類別。
#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);
}
}
}
}
open System.Net.NetworkInformation
open System.Text
// args[0] can be an IPaddress or host name.
[<EntryPoint>]
let main args =
let pingSender = new Ping()
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
let options = PingOptions()
options.DontFragment <- true
// Create a buffer of 32 bytes of data to be transmitted.
let data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
let buffer = Encoding.ASCII.GetBytes data
let timeout = 120
let reply: PingReply = pingSender.Send(args.[0], timeout, buffer, options)
match reply.Status with
| IPStatus.Success ->
printfn "Address: %O" reply.Address
printfn "RoundTrip time: %d" reply.RoundtripTime
printfn "Time to live: %d" reply.Options.Ttl
printfn "Don't fragment: %b" reply.Options.DontFragment
printfn "Buffer size: %d" reply.Buffer.Length
0
| _ ->
eprintfn "Error sending ping: %O" reply
eprintfn "Error was: %O" reply.Status
1
下列程式碼範例示範如何以非同步方式使用 Ping 類別。
#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 使用 類別來偵測遠端電腦是否可連線。
網路拓撲可以判斷是否可以 Ping 成功連絡遠端主機。 Proxy 的存在和設定、網路位址轉譯 (NAT) 設備,或防火牆可能會防止 Ping 成功。 成功 Ping 表示只能在網路上連線到遠端主機;遠端主機上有較高層級的服務 (,例如遠端主機上的網頁伺服器) 。
這個類別提供類似 Ping.exe 命令列工具的功能。 Send和 SendAsync 方法會將網際網路控制訊息通訊協定 (ICMP) 回應要求訊息傳送至遠端電腦,並等候來自該電腦的 ICMP 回應回復訊息。 如需 ICMP 訊息的詳細描述,請參閱 RFC 792,網址為 https://www.ietf.org 。
下列類型會與 類別搭配 Ping 使用,如下所述。
類型名稱 | 說明 |
---|---|
IPStatus | 定義描述 ICMP 回應要求訊息結果的狀態碼。 |
PingOptions | 可讓您設定或擷取設定,控制 () 可以轉送 Ttl 要求封包的次數,以及是否可以 DontFragment 分散 () 。 |
PingReply | 包含 ICMP 回應要求的結果。 |
PingException | 發生無法復原的錯誤時擲回。 |
PingCompletedEventArgs | 包含與事件相關聯的 PingCompleted 資料,這些事件會在呼叫完成或取消時 SendAsync 引發。 |
PingCompletedEventHandler | 委派,提供呼叫完成或取消時 SendAsync 所叫用的回呼方法。 |
Send和 SendAsync 方法會傳回 物件中的 PingReply 回復。 屬性會 PingReply.Status 傳回值 IPStatus ,以指出要求的結果。
傳送要求時,您必須指定遠端電腦。 您可以藉由提供主機名稱字串、字串格式的 IP 位址或 IPAddress 物件來執行此動作。
您也可以指定下列任一類型的資訊:
要求隨附的資料。 指定
buffer
可讓您瞭解特定大小封包往返遠端主機所需的時間,以及網路路徑的最大傳輸單位。 (請參閱 Send 採用buffer
parameter.) 的 或 SendAsync 多載ICMP Echo 封包是否可以在傳輸中分散。 (請參閱 DontFragment 採用 parameter.) 的屬性和 Send 或 SendAsync 多載
options
路由節點,例如路由器或閘道,可以轉送封包的次數,再到達目的地電腦或捨棄。 (See Ttl 和 Send 採用
options
parameter.) 的 或 SendAsync 多載
類別 Ping 同時提供傳送要求的同步和非同步方法。 如果您的應用程式應該在等候回復時封鎖,請使用 Send 方法;這些方法是同步的。 如果您的應用程式不應該封鎖,請使用非同步 SendAsync 方法。 呼叫 SendAsync 會在它自己的執行緒中執行,該執行緒會自動從執行緒集區配置。 非同步作業完成時,會引發 PingCompleted 事件。 應用程式會使用 PingCompletedEventHandler 委派來指定針對 PingCompleted 事件呼叫的方法。 您必須先將 PingCompletedEventHandler 委派新增至 事件,才能呼叫 SendAsync 。 委派的 方法會收到 PingCompletedEventArgs 物件,其中包含 PingReply 描述呼叫結果 SendAsync 的 物件。
您無法使用相同的 類別實例 Ping 來產生多個同時的 ICMP Echo 要求。 在 Send 呼叫進行中 SendAsync 或呼叫多次之前,所有先前呼叫都完成之前呼叫 SendAsync 會導致 InvalidOperationException 。
建構函式
Ping() |
初始化 Ping 類別的新執行個體。 |
屬性
CanRaiseEvents |
取得值,指出元件是否能引發事件。 (繼承來源 Component) |
Container |
取得包含 IContainer 的 Component。 (繼承來源 Component) |
DesignMode |
取得值,指出 Component 目前是否處於設計模式。 (繼承來源 Component) |
Events |
取得附加在這個 Component 上的事件處理常式清單。 (繼承來源 Component) |
Site | (繼承來源 Component) |
方法
CreateObjRef(Type) |
建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。 (繼承來源 MarshalByRefObject) |
Dispose() |
釋放 Unmanaged 資源,並處置 Ping 所使用的 Managed 資源。 |
Dispose() |
釋放 Component 所使用的所有資源。 (繼承來源 Component) |
Dispose(Boolean) |
釋放 Ping 物件所使用的 Unmanaged 資源,並選擇性處置 Managed 資源。 |
Dispose(Boolean) |
釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。 (繼承來源 Component) |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetLifetimeService() |
已淘汰.
擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。 (繼承來源 MarshalByRefObject) |
GetService(Type) |
傳回表示 Component 或其 Container 所提供之服務的物件。 (繼承來源 Component) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
InitializeLifetimeService() |
已淘汰.
取得存留期服務物件,以控制這個執行個體的存留期原則。 (繼承來源 MarshalByRefObject) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
MemberwiseClone(Boolean) |
建立目前 MarshalByRefObject 物件的淺層複本。 (繼承來源 MarshalByRefObject) |
OnPingCompleted(PingCompletedEventArgs) |
引發 PingCompleted 事件。 |
Send(IPAddress) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息,傳送給具有指定之 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 |
Send(IPAddress, Int32) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個方法可以讓您為作業指定逾時值。 |
Send(IPAddress, Int32, Byte[]) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
Send(IPAddress, Int32, Byte[], PingOptions) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定之 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 這個多載可以讓您指定作業的逾時值,以及控制 ICMP 回應訊息封包的分散和存留時間值。 |
Send(IPAddress, TimeSpan, Byte[], PingOptions) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息傳送至具有指定 IPAddress 的電腦,以及從該電腦接收對應的 ICMP 回應回復訊息。 |
Send(String) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 |
Send(String, Int32) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 這個方法可以讓您為作業指定逾時值。 |
Send(String, Int32, Byte[]) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
Send(String, Int32, Byte[], PingOptions) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可讓您指定作業的逾時值,以及控制 ICMP 封包的分散和存留時間值。 |
Send(String, TimeSpan, Byte[], PingOptions) |
嘗試將網際網路控制訊息通訊協定 (ICMP) 回應訊息傳送至指定的電腦,以及從該電腦接收對應的 ICMP 回應回復訊息。 |
SendAsync(IPAddress, Int32, Byte[], Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
SendAsync(IPAddress, Int32, Byte[], PingOptions, Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您指定作業的逾時值,以及控制 ICMP 回應訊息封包的分散和存留時間值。 |
SendAsync(IPAddress, Int32, Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,傳送給具有指定之 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
SendAsync(IPAddress, Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,傳送給具有指定之 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 |
SendAsync(String, Int32, Byte[], Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
SendAsync(String, Int32, Byte[], PingOptions, Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可讓您指定作業的逾時值,以及控制 ICMP 封包的分散和存留時間值。 |
SendAsync(String, Int32, Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
SendAsync(String, Object) |
嘗試以非同步方式將網際網路控制訊息通訊協定 (ICMP) 回應訊息傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應回覆訊息。 |
SendAsyncCancel() |
取消傳送網際網路控制訊息通訊協定 (ICMP) 回應訊息之所有暫止的非同步要求,並且接收對應的 ICMP 回應回覆訊息。 |
SendPingAsync(IPAddress) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 |
SendPingAsync(IPAddress, Int32) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
SendPingAsync(IPAddress, Int32, Byte[]) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給具有指定 IPAddress 的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可讓您指定作業的逾時值以及要用於傳送和接收作業的緩衝區。 |
SendPingAsync(IPAddress, Int32, Byte[], PingOptions) |
使用指定資料緩衝區傳送網際網路控制訊息通訊協定 (ICMP) 回應訊息到具有指定 IPAddress 的電腦,並以非同步作業方式接收來自該電腦的對應 ICMP 回應訊息。 這個多載可以讓您指定作業的逾時值、用於傳送和接收作業的緩衝區,以及控制 ICMP 回應訊息封包的分散和存留時間值。 |
SendPingAsync(IPAddress, TimeSpan, Byte[], PingOptions, CancellationToken) |
使用指定資料緩衝區傳送網際網路控制訊息通訊協定 (ICMP) 回應訊息到具有指定 IPAddress 的電腦,並以非同步作業方式接收來自該電腦的對應 ICMP 回應訊息。 此多載可讓您指定作業的逾時值、用於傳送和接收的緩衝區、控制片段和存留時間值,以及 CancellationToken ICMP 回應訊息封包的 。 |
SendPingAsync(String) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 |
SendPingAsync(String, Int32) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您為作業指定逾時值。 |
SendPingAsync(String, Int32, Byte[]) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可讓您指定作業的逾時值以及要用於傳送和接收作業的緩衝區。 |
SendPingAsync(String, Int32, Byte[], PingOptions) |
以非同步作業的方式,將網際網路控制訊息通訊協定 (ICMP) 回應訊息,連同指定的資料緩衝區一起傳送給指定的電腦,並從該電腦接收對應的 ICMP 回應的回覆訊息。 這個多載可以讓您指定作業的逾時值、用於傳送和接收作業的緩衝區,以及控制 ICMP 回應訊息封包的分散和存留時間值。 |
SendPingAsync(String, TimeSpan, Byte[], PingOptions, CancellationToken) |
傳送網際網路控制訊息通訊協定 (ICMP) 具有指定資料緩衝區的回應訊息至指定的電腦,並以非同步作業的形式從該電腦接收對應的 ICMP 回應回復訊息。 此多載可讓您指定作業的逾時值、用於傳送和接收的緩衝區、控制片段和存留時間值,以及 CancellationToken ICMP 回應訊息封包的 。 |
ToString() |
傳回任何包含 Component 名稱的 String。 不應覆寫此方法。 (繼承來源 Component) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
事件
Disposed |
當 Dispose() 方法的呼叫處置元件時,就會發生。 (繼承來源 Component) |
PingCompleted |
當傳送網際網路控制訊息通訊協定 (ICMP) 回應訊息及接收對應之 ICMP 回應回覆訊息的非同步作業完成或取消時發生。 |
明確介面實作
IDisposable.Dispose() |
釋放 Ping 類別執行個體使用的所有資源。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應