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 resolving a host name to a dot address asynchronously using the BeginGetHost method. Asynchronous use works similarly for resolving email addresses (BeginGetMailHosts).
To resolve a host name to a dot address asynchronously.
[Visual Basic, C#]
[C#] // Set the DNS server to use. dns1.Server = "MyDnsServer"; // Begin to resolve the host name. dns1.BeginGetHost("www.dart.com", null); [Visual Basic] ' Set the DNS server to use. Dns1.Server = "MyDnsServer" ' Begin to resolve the host name. Dns1.BeginGetHost("www.dart.com", Nothing)
[Visual Basic, C#]
[C# ]private void dns1_EndGetHost(object sender, Dart.PowerTCP.SslSockets.DnsEventArgs e) { // Check for any exceptions that occurred if(e.Exception == null) { // Display host name Debug.WriteLine("Host name: " + e.Host.HostName); // Display addresses, if any foreach(System.Net.IPAddress add in e.Host.AddressList) Debug.WriteLine("Address: " + add.ToString()); // Display aliases, if any foreach(string s in e.Host.Aliases) Debug.WriteLine("Aliases: " + s); } } [Visual Basic] Private Sub Dns1_EndGetHost(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.DnsEventArgs) Handles Dns1.EndGetHost ' Check for any exceptions that occurred If e.Exception Is Nothing Then ' Display host name Debug.WriteLine("Host name: " + e.Host.HostName) ' Display addresses, if any Dim add As System.Net.IPAddress For Each add In e.Host.AddressList Debug.WriteLine("Address: " + add.ToString()) Next ' Display aliases, if any Dim s As String For Each s In e.Host.Aliases Debug.WriteLine("Aliases: " + s) Next End If End Sub
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.