Answers for "c# check internet connection"

C#
1

c# check internet connection easy

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()
Posted by: Guest on May-31-2020
0

c# how to check for internet connectivity

public static bool CheckForInternetConnection(int timeoutMs = 10000, string url = null)
{
    try
    {
        url ??= CultureInfo.InstalledUICulture switch
        {
            { Name: var n } when n.StartsWith("fa") => // Iran
                "http://www.aparat.com",
            { Name: var n } when n.StartsWith("zh") => // China
                "http://www.baidu.com",
            _ =>
                "http://www.gstatic.com/generate_204",
        };

        var request = (HttpWebRequest)WebRequest.Create(url);
        request.KeepAlive = false
        request.Timeout = timeoutMs;
        using var response = (HttpWebResponse)request.GetResponse();
        return true;
    }
    catch
    {
        return false;
    }
}
Posted by: Guest on June-30-2021

Code answers related to "c# check internet connection"

C# Answers by Framework

Browse Popular Code Answers by Language