Narizz28
MIS
- Mar 8, 2001
- 161
Hi gang,
I'm a little stuck. First off let me say that I have absolutely no idea what I'm doing in VB.Net (ok, I know a little, a VERY little).
I'm trying to do a call to a Sub that does a System.Net.DNS.GetHostEntry to return a PTR record of a passed in IP address. I have it working so far thanks to the wonderful internet, but have hit a wall with one aspect of the lookup. I need it to be asynchronous of the form, i.e. leave control at the form while the lookup happens behind the scene. This way, if there a dealy in the lookup, it doesn't prevent the user from doing other things on the form.
Here's what I have so far:
This code validates without error, but doesn't return control until the called sub finishes. Obviously I either need to go back classic VB, stop trying to be a programmer (actually I'm not trying to be, I'm a sysadmin, but I'm trying my hand at a project), or turn to a marvelous life of digging ditches and forfiet to horrible defeat.
I prefer to get this figured out, but realize I need help.
More about the history so far can be found at:
I look forward to seeing where I went wrong.
Thank in advance for your help.
Narizz
I'm a little stuck. First off let me say that I have absolutely no idea what I'm doing in VB.Net (ok, I know a little, a VERY little).
I'm trying to do a call to a Sub that does a System.Net.DNS.GetHostEntry to return a PTR record of a passed in IP address. I have it working so far thanks to the wonderful internet, but have hit a wall with one aspect of the lookup. I need it to be asynchronous of the form, i.e. leave control at the form while the lookup happens behind the scene. This way, if there a dealy in the lookup, it doesn't prevent the user from doing other things on the form.
Here's what I have so far:
Code:
Public Class Form1
Delegate Sub MySubDelegate(ByVal x As String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ThisIPAddress As String = "1.2.3.4"
Dim ghn As MySubDelegate = AddressOf fGetHostName
'This is the call I am trying to do Ansychronously, so it doesn't lock up the rest of the form while it runs.
ghn.Invoke(ThisIPAddress)
End Sub
Public Sub fGetHostName(ByVal varAddress As String)
Dim varHostName As String
Threading.Thread.Sleep(10000)
varHostName = System.Net.Dns.GetHostEntry(varAddress).HostName
If varHostName = varAddress Then
PTRLabel.Text = "Could not resolve address!"
Else
PTRLabel.Text = "PTR Record is " & varHostName
End If
End Sub
Private Sub btnIncrement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIncrement.Click
Dim Count As Integer
Count = Label1.Text
Count += 1
Label1.Text = Count
End Sub
End Class
This code validates without error, but doesn't return control until the called sub finishes. Obviously I either need to go back classic VB, stop trying to be a programmer (actually I'm not trying to be, I'm a sysadmin, but I'm trying my hand at a project), or turn to a marvelous life of digging ditches and forfiet to horrible defeat.
I prefer to get this figured out, but realize I need help.
More about the history so far can be found at:
I look forward to seeing where I went wrong.
Thank in advance for your help.
Narizz