Use
InternetGetConnectedState[
^] function. And then use
InternetCheckConnection[
^] function. A sample code:
using System;
using System.Runtime;
using System.Runtime.InteropServices;
public class InternetCS
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState( out int Description, int ReservedValue );
public static bool IsConnectedToInternet( )
{
int Desc ;
return InternetGetConnectedState( out Desc, 0 ) ;
}
}
-OR-
WebClient web = new WebClient();
try
{
web.DownloadData("http://www.codeproject.com");
}
catch (WebException ex)
{
Console.WriteLine("Could not connect");
}
If it fails you do not have conenction. But 1 st way is more reliable in my opinion.
Good luck,
OI