Редагувати

Поділитися через


Ping.SendPingAsync Method

Definition

Sends an Internet Control Message Protocol (ICMP) echo message to a computer, and receives a corresponding ICMP echo reply message from that computer as an asynchronous operation.

Overloads

SendPingAsync(String, TimeSpan, Byte[], PingOptions, CancellationToken)

Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, 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, a buffer to use for send and receive, control fragmentation and Time-to-Live values, and a CancellationToken for the ICMP echo message packet.

SendPingAsync(IPAddress)

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(String)

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(IPAddress, Int32)

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(String, Int32)

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(IPAddress, Int32, Byte[])

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(String, Int32, Byte[])

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(IPAddress, Int32, Byte[], PingOptions)

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. 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, Int32, Byte[], PingOptions)

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, a buffer to use for send and receive, and control fragmentation and Time-to-Live values for the ICMP echo message packet.

SendPingAsync(IPAddress, TimeSpan, Byte[], PingOptions, CancellationToken)

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. This overload allows you to specify a time-out value for the operation, a buffer to use for send and receive, control fragmentation and Time-to-Live values, and a CancellationToken for the ICMP echo message packet.

Remarks

The IP address returned by any of the SendPingAsync methods can originate from a malicious remote computer. Do not connect to the remote computer using this. Use DNS to determine the IP address of the machine to which you want to connect.

SendPingAsync(String, TimeSpan, Byte[], PingOptions, CancellationToken)

Source:
Ping.cs
Source:
Ping.cs

Sends an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the specified computer, 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, a buffer to use for send and receive, control fragmentation and Time-to-Live values, and a CancellationToken for the ICMP echo message packet.

public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (string hostNameOrAddress, TimeSpan timeout, byte[]? buffer = default, System.Net.NetworkInformation.PingOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
member this.SendPingAsync : string * TimeSpan * byte[] * System.Net.NetworkInformation.PingOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (hostNameOrAddress As String, timeout As TimeSpan, Optional buffer As Byte() = Nothing, Optional options As PingOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of PingReply)

Parameters

hostNameOrAddress
String

The computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.

timeout
TimeSpan

The amount of time (after sending the echo message) to wait for the ICMP echo reply message.

buffer
Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

options
PingOptions

A PingOptions object used to control fragmentation and Time-to-Live values for the ICMP echo message packet.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

The task object representing the asynchronous operation.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

SendPingAsync(IPAddress)

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::Net::IPAddress ^ address);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (System.Net.IPAddress address);
member this.SendPingAsync : System.Net.IPAddress -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (address As IPAddress) As Task(Of PingReply)

Parameters

address
IPAddress

An IP address that identifies the computer that is the destination for the ICMP echo message.

Returns

The task object representing the asynchronous operation.

Exceptions

address is null.

A call to SendPingAsync is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

address is not a valid IP address.

This object has been disposed.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

SendPingAsync(String)

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::String ^ hostNameOrAddress);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (string hostNameOrAddress);
member this.SendPingAsync : string -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (hostNameOrAddress As String) As Task(Of PingReply)

Parameters

hostNameOrAddress
String

The computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.

Returns

The task object representing the asynchronous operation.

Exceptions

hostNameOrAddress is null or is an empty string ("").

A call to SendAsync(String, Object) method is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

hostNameOrAddress could not be resolved to a valid IP address.

This object has been disposed.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

SendPingAsync(IPAddress, Int32)

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::Net::IPAddress ^ address, int timeout);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (System.Net.IPAddress address, int timeout);
member this.SendPingAsync : System.Net.IPAddress * int -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (address As IPAddress, timeout As Integer) As Task(Of PingReply)

Parameters

address
IPAddress

An IP address that identifies the computer that is the destination for the ICMP echo message.

timeout
Int32

The maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

Returns

The task object representing the asynchronous operation.

Exceptions

address is null.

A call to the SendAsync method is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

address is not a valid IP address.

This object has been disposed.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

SendPingAsync(String, Int32)

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::String ^ hostNameOrAddress, int timeout);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (string hostNameOrAddress, int timeout);
member this.SendPingAsync : string * int -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (hostNameOrAddress As String, timeout As Integer) As Task(Of PingReply)

Parameters

hostNameOrAddress
String

The computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.

timeout
Int32

The maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

Returns

The task object representing the asynchronous operation.

Exceptions

address is null.

timeout is less than zero.

A call to the SendAsync method is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

address is not a valid IP address.

This object has been disposed.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

SendPingAsync(IPAddress, Int32, Byte[])

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::Net::IPAddress ^ address, int timeout, cli::array <System::Byte> ^ buffer);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (System.Net.IPAddress address, int timeout, byte[] buffer);
member this.SendPingAsync : System.Net.IPAddress * int * byte[] -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (address As IPAddress, timeout As Integer, buffer As Byte()) As Task(Of PingReply)

Parameters

address
IPAddress

An IP address that identifies the computer that is the destination for the ICMP echo message.

timeout
Int32

The maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

buffer
Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

Returns

The task object representing the asynchronous operation.

Exceptions

address or buffer is null.

timeout is less than zero.

A call to SendPingAsync is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

address is not a valid IP address.

This object has been disposed.

The size of buffer exceeds 65,500 bytes.

.NET 7 and later versions only on Linux: The process is non-privileged, and buffer is not empty.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

SendPingAsync(String, Int32, Byte[])

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::String ^ hostNameOrAddress, int timeout, cli::array <System::Byte> ^ buffer);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (string hostNameOrAddress, int timeout, byte[] buffer);
member this.SendPingAsync : string * int * byte[] -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (hostNameOrAddress As String, timeout As Integer, buffer As Byte()) As Task(Of PingReply)

Parameters

hostNameOrAddress
String

The computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.

timeout
Int32

The maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

buffer
Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

Returns

The task object representing the asynchronous operation.

Exceptions

hostNameOrAddress is null or is an empty string ("").

-or-

buffer is null.

timeout is less than zero.

A call to SendAsync is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

hostNameOrAddress could not be resolved to a valid IP address.

This object has been disposed.

The size of buffer exceeds 65500 bytes.

.NET 7 and later versions only on Linux: The process is non-privileged, and buffer is not empty.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

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

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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. 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.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::Net::IPAddress ^ address, int timeout, cli::array <System::Byte> ^ buffer, System::Net::NetworkInformation::PingOptions ^ options);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options);
member this.SendPingAsync : System.Net.IPAddress * int * byte[] * System.Net.NetworkInformation.PingOptions -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (address As IPAddress, timeout As Integer, buffer As Byte(), options As PingOptions) As Task(Of PingReply)

Parameters

address
IPAddress

An IP address that identifies the computer that is the destination for the ICMP echo message.

timeout
Int32

The maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

buffer
Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

options
PingOptions

A PingOptions object used to control fragmentation and Time-to-Live values for the ICMP echo message packet.

Returns

The task object representing the asynchronous operation.

Exceptions

address or buffer is null.

timeout is less than zero.

A call to SendPingAsync is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

address is not a valid IP address.

This object has been disposed.

The size of buffer exceeds 65,500 bytes.

.NET 7 and later versions only on Linux: The process is non-privileged, and buffer is not empty.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

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

Source:
Ping.cs
Source:
Ping.cs
Source:
Ping.cs

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, a buffer to use for send and receive, and control fragmentation and Time-to-Live values for the ICMP echo message packet.

public:
 System::Threading::Tasks::Task<System::Net::NetworkInformation::PingReply ^> ^ SendPingAsync(System::String ^ hostNameOrAddress, int timeout, cli::array <System::Byte> ^ buffer, System::Net::NetworkInformation::PingOptions ^ options);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options);
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options);
member this.SendPingAsync : string * int * byte[] * System.Net.NetworkInformation.PingOptions -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (hostNameOrAddress As String, timeout As Integer, buffer As Byte(), options As PingOptions) As Task(Of PingReply)

Parameters

hostNameOrAddress
String

The computer that is the destination for the ICMP echo message. The value specified for this parameter can be a host name or a string representation of an IP address.

timeout
Int32

The maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.

buffer
Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

options
PingOptions

A PingOptions object used to control fragmentation and Time-to-Live values for the ICMP echo message packet.

Returns

The task object representing the asynchronous operation.

Exceptions

hostNameOrAddress is null or is an empty string ("").

-or-

buffer is null.

timeout is less than zero.

A call to SendAsync is in progress.

An exception was thrown while sending or receiving the ICMP messages. See the inner exception for the exact exception that was thrown.

hostNameOrAddress could not be resolved to a valid IP address.

This object has been disposed.

The size of buffer exceeds 65500 bytes.

.NET 7 and later versions only on Linux: The process is non-privileged, and buffer is not empty.

Remarks

This operation will not block. The returned Task<TResult>> object will complete after the ICMP packet has been sent and the response has been received.

Applies to

SendPingAsync(IPAddress, TimeSpan, Byte[], PingOptions, CancellationToken)

Source:
Ping.cs
Source:
Ping.cs

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. This overload allows you to specify a time-out value for the operation, a buffer to use for send and receive, control fragmentation and Time-to-Live values, and a CancellationToken for the ICMP echo message packet.

public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync (System.Net.IPAddress address, TimeSpan timeout, byte[]? buffer = default, System.Net.NetworkInformation.PingOptions? options = default, System.Threading.CancellationToken cancellationToken = default);
member this.SendPingAsync : System.Net.IPAddress * TimeSpan * byte[] * System.Net.NetworkInformation.PingOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply>
Public Function SendPingAsync (address As IPAddress, timeout As TimeSpan, Optional buffer As Byte() = Nothing, Optional options As PingOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of PingReply)

Parameters

address
IPAddress

An IP address that identifies the computer that is the destination for the ICMP echo message.

timeout
TimeSpan

The amount of time (after sending the echo message) to wait for the ICMP echo reply message.

buffer
Byte[]

A Byte array that contains data to be sent with the ICMP echo message and returned in the ICMP echo reply message. The array cannot contain more than 65,500 bytes.

options
PingOptions

A PingOptions object used to control fragmentation and Time-to-Live values for the ICMP echo message packet.

cancellationToken
CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

The task object representing the asynchronous operation.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Applies to