Asynchronously attempts to send an Internet Control Message Protocol (ICMP) echo message with the specified data buffer to the computer that has the specified System.Net.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.
- address
- An System.Net.IPAddress that identifies the computer that is the destination for the ICMP echo message.
- timeout
- An int value that specifies the maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.
- buffer
- 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.
- userToken
- An object that is passed to the method invoked when the asynchronous operation completes.
This method sends the echo message asynchronously and, when the operation completes (successfully or unsuccessfully), returns the status to your application. Call the erload:System.Net.NetworkInformation.Ping.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 Ping.PingCompleted event. To specify the method that is called when erload:System.Net.NetworkInformation.Ping.SendAsync raises the event, you must add a System.Net.NetworkInformation.PingCompletedEventHandler delegate to the event before calling erload:System.Net.NetworkInformation.Ping.SendAsync. The delegate's method receives a System.Net.NetworkInformation.PingCompletedEventArgs object that contains a System.Net.NetworkInformation.PingReply object that describes the result of the erload:System.Net.NetworkInformation.Ping.SendAsync call. The System.Net.NetworkInformation.PingCompletedEventArgs object inherits the System.ComponentModel.AsyncCompletedEventArgs.UserState property. This property contains the userToken object passed into the erload:System.Net.NetworkInformation.Ping.SendAsync call.
If your application blocks while waiting for a reply, use the erload:System.Net.NetworkInformation.Ping.Send methods; these methods are synchronous.
If the ICMP echo reply message is not received within the time specified by the timeout parameter, the ICMP echo fails, and the PingReply.Status property is set to IPStatus.TimedOut.
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 erload:System.Net.NetworkInformation.Ping.SendAsync methods that takes an options parameter, and set the PingOptions.DontFragment property to true. When PingOptions.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 PingReply.Status is set to IPStatus.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 erload:System.Net.NetworkInformation.Ping.SendAsync overload that takes an options parameter, and set the PingOptions.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 PingReply.Status is set to IPStatus.TtlExpired.