Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer with event handler - tough one!!!!!!

Status
Not open for further replies.

june1980

MIS
Jun 16, 2003
93
0
0
US
Here's an overview. I want a sub called "ServerTimerElapsed" to run every 30 seconds. To do this, I'm using an event handler that triggers the above sub. The event handler works, and the sub runs. However, when it does run, it stops at the third line (dim stream...) and stops cold! No error message. It compiles without error. Any ideas? It works fine when not triggered by the event handler.


Here's the plan. I want to make the following happen.

Private Sub ServerTimerElapsed(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim SocketTest As Boolean
Dim HostEP As New System.Net.IPEndPoint(System.Net.Dns.GetHostByAddress(GlobalIP).AddressList(0), CurrentPort)
Dim Stream As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
Dim Progress As String
SocketTest = True
HostEP = New System.net.IPEndPoint(System.Net.Dns.GetHostByAddress(GlobalIP).AddressList(0), txtPortMon.Text)
Try
Stream.Connect(HostEP)
Catch ex As Exception
SocketTest = False
End Try
If SocketTest = True Then
lblMonStat.Text = FQDN & " running " & txtPortMon.Text
End If
End Sub

The event I want to trigger this is....

AddHandler ServerTimer.Elapsed, AddressOf ServerTimerElapsed
 
Code:
 Dim HostEP As New System.Net.IPEndPoint(System.Net.Dns.GetHostByAddress(GlobalIP).AddressList(0), CurrentPort)
It's doing a reverse DNS lookup. This may take some time -- but it should return within 30 seconds. Note that it might not find a DNS address at all, so looking at AddressList(0) in the same line is probably not a safe thing to do (since element 0 might not exist).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
I wish that had something to do with it, but if I move that the code outside the ServerTimerElapsed sub, then it works fine. Only when the event is triggered by an event handler that fires on a timer does it not work. It's almost like it's missing a DLL or something...
 
Try breaking that line up into separate statements. This should help you narrow it down.

Also - are you 100% sure that that line is the one causing the problem?

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks Chip. I figured it out. The it had to do with the event handler.

Breaking the line up would have helped me, and I'll do that in the future, so I'll give you a vote :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top