c# detect when an internet connection is established code example
Example 1: check connection c#
public static bool CheckForInternetConnection()
{
try
{
using (var client = new WebClient())
using (client.OpenRead("http://google.com/generate_204"))
return true;
}
catch
{
return false;
}
}
Example 2: c# check internet connection easy
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()