WEBClient (Unable To Connect To Remote Server)
Ok so..
I need to read a command from a .html file. To do this I use:
Code:
Dim instance As WebClient = New WebClient
Dim address As String = "www.siteurl.com/file.html"
Dim returnValue As String
returnValue = instance.DownloadString(address)
If returnValue = "open" Then
BLAHBLAHBLAH
I need this to run flawlessly, regardless if the my internet is on or not. If the internet disconnects, I get this (While Debugging):
returnValue = instance.DownloadString(address)
Unable to connect to the remote server
Question:
My application constantly loops to check the .html file for commands.
I need it to do this, even if the internet is off. Obviously, it wont read commands if its off.. I just need it to resume reading when it comes back on WITHOUT crashing my application.
Any code to ignore timeouts so where my application will still TRY to read and not crash.
Re: WEBClient (Unable To Connect To Remote Server)
Code:
Try
returnValue = instance.DownloadString(address)
Catch ex as Exception
Debug.WriteLine("Timeout... Ignoring...zzz")
End Try
More here:
http://support.microsoft.com/kb/315965
Re: WEBClient (Unable To Connect To Remote Server)
Thank you. It worked, although I did get this:
Variable 'returnValue' is used before it has been assigned a value. A null reference exception could result at runtime
Doesnt seem to be causing any trouble though.
Re: WEBClient (Unable To Connect To Remote Server)
it's a warning, not an error. You have no guarantees that 'returnValue' would hold a valid reference. In your case it's nothing to worry about since it's a string. The compiler just points it out to you. If it worries you you can declare it with initialization:
Code:
Dim returnValue As String = ""
The warning will go away.