I wrote this function to check if an internet connection is available:
bool IsOnline()
{
try
{
var request = (HttpWebRequest)WebRequest.CreateHttp("http://www.google.com/");
request.Timeout = 2000;
var response = (HttpWebResponse)request.GetResponse();
return ((int)response.StatusCode) < 400;
}
catch (Exception) { return false; }
}
It seems to work in almost all cases however under my work network it return false after a timeout error while the connection is available.
Note: - this function return false but I can go online with a webbrowser component in my WPF application - the connection is pretty good. (so it is impossible to spend more than 2sec in loading google.com) - I'm behind a proxy configured correctly in Control Panel/Internet Options/Connection
Any ideas?