Skip to content

Instantly share code, notes, and snippets.

@LoriBru
Created January 14, 2019 11:32
Show Gist options
  • Select an option

  • Save LoriBru/a026d062b5a5eb49989ecf912a258bc6 to your computer and use it in GitHub Desktop.

Select an option

Save LoriBru/a026d062b5a5eb49989ecf912a258bc6 to your computer and use it in GitHub Desktop.
This method check the presence of internet connection.
public static bool CheckConnection()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.microsoft.com");
request.Timeout = 5000;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
return true;
else
return false;
}
catch
{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment