Glossary Item Box
Asynchronous operations are useful because they occur without waiting for the action to complete before executing the next line of code. Such a technique is useful when an operation is time consuming and other code needs to execute without waiting for the operation to complete. The following example demonstrates pinging a host asynchronously using the BeginSend method.
To ping a host asynchronously.
[Visual Basic, C#]
[C#] // Begin the ping. ping1.BeginSend("www.dart.com", null); [Visual Basic] ' Begin the ping. Ping1.BeginSend("www.dart.com", Nothing)
[Visual Basic, C#]
[C#] private void ping1_EndSend(object sender, Dart.PowerTCP.SslSockets.PingEventArgs e) { if(e.Exception == null) { // EchoResult er describes the ping. Display properties of the EchoResult. Debug.WriteLine("Reply from " + e.Result.RemoteAddress); Debug.WriteLine("Bytes " + e.Result.Data.Length); Debug.WriteLine("Time " + e.Result.ResponseTime); Debug.WriteLine("TTL " + e.Result.TTL); } else Debug.WriteLine(e.Exception.Message); } [Visual Basic] Private Sub Ping1_EndSend(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.PingEventArgs) Handles Ping1.EndSend If Not e.Exception Is Nothing Then ' EchoResult er describes the ping. Display properties of the EchoResult. Debug.WriteLine("Reply from " + e.Result.RemoteAddress) Debug.WriteLine("Bytes " + e.Result.Data.Length) Debug.WriteLine("Time " + e.Result.ResponseTime) Debug.WriteLine("TTL " + e.Result.TTL) Else Debug.WriteLine(e.Exception.Message) End If End Sub
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.