J
Jerry Spence1
I start up a thread which does this:
Sub ReaderThread
Dim tcpCli As New TcpClient
Try
tcpCli.Connect("100.21.0.5", 2101)
Catch
tcpCli.Close()
End Try
End Sub
This connects OK. If there is a problem, then tcpCli closes and the thread
terminates.
I have a separate ThreadMonitor on a Timer which triggers every 2 seconds.
If it detects that the above thread has failed it restarts it as follows:
Dim t1 As New Thread(New ThreadStart(AddressOf ReaderThread))
t1.Start()
The problem is that when I get to the line:
tcpCli.Connect("100.21.0.5", 2101)
It fails to connect, and ends up in the Catch section and terminates again.
If I start the program again, it connects OK. It's as though somehow a
resource is not being cleared.
However I can do
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
forever, and it works OK.
I'm mystified.
-Jerry
Sub ReaderThread
Dim tcpCli As New TcpClient
Try
tcpCli.Connect("100.21.0.5", 2101)
Catch
tcpCli.Close()
End Try
End Sub
This connects OK. If there is a problem, then tcpCli closes and the thread
terminates.
I have a separate ThreadMonitor on a Timer which triggers every 2 seconds.
If it detects that the above thread has failed it restarts it as follows:
Dim t1 As New Thread(New ThreadStart(AddressOf ReaderThread))
t1.Start()
The problem is that when I get to the line:
tcpCli.Connect("100.21.0.5", 2101)
It fails to connect, and ends up in the Catch section and terminates again.
If I start the program again, it connects OK. It's as though somehow a
resource is not being cleared.
However I can do
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
tcpCli.Connect("100.21.0.5", 2101)
tcpCli.close()
forever, and it works OK.
I'm mystified.
-Jerry