Horje
check connection c# Code Example
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;
    }
}
check connection c#

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;
    }
}

Source: devarama.com




Csharp

Related
Uncaught TypeError: $(...).validate is not a function Code Example Uncaught TypeError: $(...).validate is not a function Code Example
how to run an external program with c# Code Example how to run an external program with c# Code Example
how to delete all files in a directory c# Code Example how to delete all files in a directory c# Code Example
unity textmeshpro Code Example unity textmeshpro Code Example
how to change image color unity Code Example how to change image color unity Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10