views:

64

answers:

2

Hi,

I need a way to determine internet availability programmatically. At now i use Ping to constantly ping some internet site.

But it seems Windows 7 though determines internet availability in some other way. If computer is online there is earth icon on the network interface icon in the System Tray.

The question is: is there any standard Win32 way to check online status, win event or something, and if so, how to use it from C#?

+3  A: 

I believe something like this would work although your question appears to be a duplicate:

using System;
using System.Runtime;
using System.Runtime.InteropServices;

public class InternetCS
{
    //Creating the extern function...
    [DllImport("wininet.dll")]
    private extern static bool InternetGetConnectedState( out int Description, int ReservedValue );

    //Creating a function that uses the API function...
    public static bool IsConnectedToInternet( )
    {
        int Desc ;
        return InternetGetConnectedState( out Desc, 0 ) ;
    }
}

forund here:

http://stackoverflow.com/questions/1085045/check-whether-internet-connection-is-available-with-c

Michael Eakins
+2  A: 

'Connected to the Internet' doesn't have any actual meaning except in the case of a modem. The beat way to test whether any resource is available is to use it. You have to cope with failures at that point anyway, no need to code everything twice.

EJP
Well, it is already done so. Every 3 seconds i send ping to a public whell-known host and if i fail for at least 10 cycles - i reboot network interface.
skaeff