Ping.SendAsync Method (IPAddress, Int32, Byte(), Object)
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.
Assembly: System (in System.dll)
'Declaration <HostProtectionAttribute(SecurityAction.LinkDemand, ExternalThreading := True)> _ Public Sub SendAsync ( _ address As IPAddress, _ timeout As Integer, _ buffer As Byte(), _ userToken As Object _ )
- Type: System.Net.IPAddress
An IPAddress that identifies the computer that is the destination for the ICMP echo message.
- Type: System.Int32
An Int32 value that specifies the maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.
- Type: System.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.
- Type: System.Object
An object that is passed to the method invoked when the asynchronous operation completes.
address is Nothing.
buffer is Nothing.
timeout is less than zero.
A call to SendAsync is in progress.
address is an IPv6 address and the local computer is running an operating system earlier than Windows 2000.
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 65500 bytes.
This method sends the echo message asynchronously and, when the operation completes (successfully or unsuccessfully), returns the status to your application. Call the SendAsync method when your application should not block. Each call executes in a separate thread that is automatically allocated from the thread pool. When the asynchronous operation completes, it raises the PingCompleted event. To specify the method that is called when SendAsync raises the event, you must add a PingCompletedEventHandler delegate to the event before calling SendAsync. The delegate's method receives a PingCompletedEventArgs object that contains a PingReply object that describes the result of the SendAsync call. The PingCompletedEventArgs object inherits the UserState property. This property contains the userToken object passed into the SendAsync call.
If your application blocks while waiting for a reply, use the Send methods; these methods are synchronous.
When specifying very small numbers for timeout, the Ping reply can be received even if timeout milliseconds have elapsed.
This overload uses default settings for packet fragmentation and packet forwarding. The packet that contains the ICMP echo message can be fragmented in transit if the total packet size exceeds the maximum packet size that can be transmitted by one of the routing nodes between the local and remote computers. To prevent fragmentation, use one of the SendAsync methods that takes an options parameter, and set the DontFragment property to true. When DontFragment is true and the total packet size exceeds the maximum packet size that can be transmitted by one of the routing nodes between the local and remote computers, the ICMP echo request fails. When this happens, the Status is set to PacketTooBig. The packet or packet fragments (if fragmented) can be forwarded by routing nodes 128 times before being discarded. To change this setting, use a SendAsync overload that takes an options parameter, and set the Ttl property to the desired value. If the packet does not reach its destination after being forwarded the specified number of times, the packet is discarded and the ICMP echo request fails. When this happens, the Status is set to TtlExpired.
The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.