Hi,
I am trying to develop a thread where it continuously checks if there is a network connection. Following is the code I am using. It only works fine for the first time, after that it does not realise that either a connection is established or lost. Can any one please help?
Dim threadCheckInternetConnection As New Thread(AddressOf Me.TestConnection)
threadCheckInternetConnection.Priority = ThreadPriority.Highest
threadCheckInternetConnection.Start()
Private Sub TestConnection()
Dim blContinueForEver As Boolean = True
Dim objUrl As New System.Uri("
While blContinueForEver
' Setup WebRequest
Dim objWebReq As System.Net.WebRequest
objWebReq = System.Net.WebRequest.Create(objUrl)
Dim objResp As System.Net.WebResponse
Try
' Attempt to get response and return True
objResp = objWebReq.GetResponse
objWebReq = Nothing
TextBox1.Text = "Connection Established"
Catch ex As Exception
' Error, exit and return False
objWebReq = Nothing
TextBox1.Text = "No Connection"
End Try
objResp = Nothing
End While
End Sub
Thanks in advance,
I am trying to develop a thread where it continuously checks if there is a network connection. Following is the code I am using. It only works fine for the first time, after that it does not realise that either a connection is established or lost. Can any one please help?
Dim threadCheckInternetConnection As New Thread(AddressOf Me.TestConnection)
threadCheckInternetConnection.Priority = ThreadPriority.Highest
threadCheckInternetConnection.Start()
Private Sub TestConnection()
Dim blContinueForEver As Boolean = True
Dim objUrl As New System.Uri("
While blContinueForEver
' Setup WebRequest
Dim objWebReq As System.Net.WebRequest
objWebReq = System.Net.WebRequest.Create(objUrl)
Dim objResp As System.Net.WebResponse
Try
' Attempt to get response and return True
objResp = objWebReq.GetResponse
objWebReq = Nothing
TextBox1.Text = "Connection Established"
Catch ex As Exception
' Error, exit and return False
objWebReq = Nothing
TextBox1.Text = "No Connection"
End Try
objResp = Nothing
End While
End Sub
Thanks in advance,