Figure internet connectivity or webpage accessibility

  • Thread starter Thread starter DotNetMania
  • Start date Start date
D

DotNetMania

when i want to know internet connection i use below code ..

WebRequest Request = WebRequest.Create(new Uri( HOME ));

if (Request.GetResponse().ToString().Length > 0)
{
result = true;
}

but this code is so delay..

are there the other method to solve this problem..?
 
DotNetMania,

You can call the InternetGetConnectedStateEx function in the WinInet
library through the P/Invoke layer to do this. You can use this code:

[DllImport("WinInet.dll", CharSet=CharSet.Auto)]
public static extern bool InternetGetConnectedStateEx(
[MarshalAs(UnmanagedType.U4)] int lpdwFlags,
StringBuilder lpszConnectionName,

[MarshalAs(UnmanagedType.U4)] int dwNameLen,
[MarshalAs(UnmanagedType.U4)] int dwReserved);

You can get the values to pass in from the documentation for this
function.

Hope this helps.
 
Back
Top