Export (0) Print
Expand All

Ping.SendAsync Method (IPAddress, Object)

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.

Namespace: System.Net.NetworkInformation
Assembly: System (in system.dll)

public void SendAsync (
	IPAddress address,
	Object userToken
)
public void SendAsync (
	IPAddress address, 
	Object userToken
)
public function SendAsync (
	address : IPAddress, 
	userToken : Object
)
Not applicable.

Parameters

address

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

userToken

An object that is passed to the method invoked when the asynchronous operation completes.

Exception typeCondition

ArgumentNullException

address is a null reference (Nothing in Visual Basic).

InvalidOperationException

A call to the SendAsync method is in progress.

NotSupportedException

address is an IPv6 address and the local computer is running an operating system earlier than Windows 2000.

PingException

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

SocketException

address is not a valid IP address.

ObjectDisposedException

This object has been disposed.

The SendAsync 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 to this method 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.

NoteNote:

If your application should block while waiting for a reply, use one of the Send methods; these methods are synchronous.

This method sends a 32 Byte data buffer with the ICMP echo message. The method waits five seconds for an ICMP echo reply message. If it does not receive a reply in that time, the method returns and the Status property is set to TimedOut.

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

For a code example that demonstrates calling a SendAsync method, see the Ping class overview.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft