Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Asynchronous DNS Abort
Visual Basic sample program showing how to abort an asynchronous DNS query. ' Demonstrates how to do an asynchronous DNS lookup, with abort capability.
' Create a Chilkat Socket object and unlock.
Set socket = New ChilkatSocket
success = socket.UnlockComponent("Anything for 30-day trial")
If (success = 0) Then
MsgBox "Failed to unlock component"
Exit Sub
End If
Dim hostname As String
' You may wish to test the code with both valid and invalid hostnames.
'hostname = "www.123abc32893489.com"
hostname = "www.chilkatsoft.com"
' Wait a maximum of 10 seconds (10000 milliseconds)
maxWaitMs = 10000
' If AsyncDnsStart returns 0, it failed. It can only fail if
' an asynchronous DNS lookup is already in progress.
success = socket.AsyncDnsStart(hostname, maxWaitMs)
If (success = 0) Then
MsgBox socket.LastErrorText
Exit Sub
End If
' Your program may now continue while the DNS query is proceeding in a
' background thread.
' You can abort the background thread at any point by calling AsyncDnsAbort:
' If the DNS lookup completes or fails quickly, the abort
' may not be reflected in the results.
socket.AsyncDnsAbort
' Uncomment this loop to wait for the DNS query to complete.
'Do
' socket.SleepMs 10
'Loop Until socket.AsyncDnsFinished
' You can check the completion status by:
If (socket.AsyncDnsFinished = 1) Then
MsgBox "Background DNS lookup thread is finished"
' If finished, you can check the success/failure status:
If (socket.AsyncDnsSuccess = 1) Then
' if successful, the IP address is available (in XXX.XXX.XXX.XXX string form)
' in the AsyncDnsResult property.
MsgBox socket.AsyncDnsResult
Else
' if not successful, the error log is available in AsyncDnsLog:
MsgBox socket.AsyncDnsLog
End If
Else
MsgBox "Background DNS lookup thread is still running"
End If
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.