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 performing a trace route operation asynchronously using the BeginSend method.
To perform an asynchronous trace route operation:
[Visual Basic, C#]
[C#] // Set all hops and echoes to be synchronous trace1.HopType = HopType.SynchHops; // Begin the trace. trace1.BeginSend("www.dart.com", null); [Visual Basic] ' Set all hops and echoes to be synchronous Trace1.HopType = SynchHops ' Begin the trace. Trace1.BeginSend("www.dart.com", Nothing)
[Visual Basic, C#]
[C#] private void trace1_Hop(object sender, Dart.PowerTCP.SslSockets.HopEventArgs e) { // Check for any exceptions if(e.Exception == null) { // Display information about the hop Debug.WriteLine("Time-to-live for the hop: " + e.Result.TTL); Debug.WriteLine("Remote address: " + e.Result.RemoteAddress); // Now display info about each of the three echoes Debug.WriteLine("Response times for this hop"); foreach(EchoResult er in e.Result.Echoes) Debug.WriteLine(er.ResponseTime); } } [Visual Basic] Private Sub Trace1_Hop(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.HopEventArgs) Handles Trace1.Hop ' Check for any exceptions If e.Exception Is Nothing Then ' Display information about the hop Debug.WriteLine("Time-to-live for the hop: " & e.Result.TTL) Debug.WriteLine("Remote address: " & e.Result.RemoteAddress) ' Now display info about each of the three echoes Debug.WriteLine("Response times for this hop") Dim er As EchoResult For Each er In e.Result.Echoes Debug.WriteLine(er.ResponseTime) Next End If End Sub
[Visual Basic, C#]
[C#] private void trace1_EndSend(object sender, Dart.PowerTCP.SslSockets.TraceEventArgs e) { // Check for any exceptions if(e.Exception == null) // Trace operation completed successfully, display info. Debug.WriteLine("Total hops: " + e.Result.Hops.Length); else Debug.WriteLine("Exception: " + e.Exception.Message); } [Visual Basic] Private Sub Trace1_EndSend(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.TraceEventArgs) Handles Trace1.EndSend ' Check for any exceptions If e.Exception Is Nothing Then ' Trace operation is complete, display info. Debug.WriteLine("Total hops: " & e.Result.Hops.Length) Else Debug.WriteLine("Exception: " & e.Exception.Message) End If End Sub
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.