Created
March 5, 2015 07:35
-
-
Save yemrekeskin/df052c9a464cb0c9a4e2 to your computer and use it in GitHub Desktop.
Check Internet Connection with c#
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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if(CheckInternetConnection()) | |
Console.WriteLine("Internet var"); | |
else Console.WriteLine("Internet yok"); | |
Console.ReadLine(); | |
} | |
public static bool CheckInternetConnection() | |
{ | |
try | |
{ | |
using (var client = new WebClient()) | |
using (var stream = client.OpenRead("http://www.google.com")) | |
{ | |
return true; | |
} | |
} | |
catch | |
{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Biyuktul Yes, use
HttpClient
instead.I'm on mobile and just going off of memory for the class names but that should be pretty close.