-
Aug 15th, 2013, 12:32 PM
#1
Thread Starter
New Member
Detecting network connection loss
I am writing a program in vb 2010 express that relies on being connected to the internet, I want to be able to capture a Windows Message and close my program or log when the network connection is lost, either by Wifi being turned off or the network cable being unplugged.
I am using My.Computer.Network.Ping() to determine if it is connected when the application starts, but I need to be able to monitor it on an ongoing basis. I assume there is a Windows Message that gets broadcasted as the network adaptor status changes, can anyone provide me a chunk of code that would capture this?
Any assistance is greatly appreciated.
~probiefireman
-
Aug 15th, 2013, 02:11 PM
#2
Re: Detecting network connection loss
there might be... there might not be... but I can think of a case where it wouldn't work:
the internet connection goes down but the WiFi connection, or the connection to the router/network is still good... I've had cases where the modem disconnects, but the computer is still connected to the router (separate from the modem) which is still up, so it doesn't always realize the internet connection is down.
-tg
-
Aug 16th, 2013, 06:55 AM
#3
New Member
Re: Detecting network connection loss
If its for local network its possible otherwise for WAN network or other it would prove to be difficult though do-able.
http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx
As An Example;
Code:
If My.Computer.Network.Ping("198.01.01.01") Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
or
Code:
If My.Computer.Network.Ping("www.cohowinery.com",1000) Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
-
Aug 24th, 2013, 12:54 AM
#4
Re: Detecting network connection loss
I'mnot sure if this thread is still 'active' but I wouldn't recommend Pinging as it consumes network bandwidth.
Presumably there are parts of your program that will require to access something over the network. Should the network not be avaiable when accessing, an Exception will be thrown, all you need to do is Catch that exception and do whatever you need to do under those circumstances.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|