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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thread only runs right once

Status
Not open for further replies.

adalli

Programmer
Feb 8, 2005
44
MT
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,
 
Is there a way how I can avoid this?
 
upgrade to 2005 and use my.... can't remember the exact words.

And then you would need to rewrite your code because it is updating controls on a form in an unsafe matter.

if you want to use tek-tips as a url you could try the different forums to connect to.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
You'll have to excuse Chrissie, some people have already received their free 2k5 disk and there appears to be some side effects. ;)

Flip through the webrequest object's properties and methods, see if there are any chaching or forced refresh options. You could also try forcing the garbage collector to run to remove your webclient from memory. But if the cache is happening in a Proxi server, you're pretty well stuck.

If you are just looking for a local area connection, you could try pinging your DNS host.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top