Results 1 to 4 of 4

Thread: Detecting network connection loss

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2013
    Posts
    1

    Exclamation 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

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    New Member
    Join Date
    May 2013
    Posts
    14

    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

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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
  •  



Click Here to Expand Forum to Full Width