Created
January 14, 2019 11:32
-
-
Save LoriBru/a026d062b5a5eb49989ecf912a258bc6 to your computer and use it in GitHub Desktop.
This method check the presence of internet connection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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