Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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

PREVIOUS NEXT
Code Example
Csharp :: c# create array with n elements 
Csharp :: join array in c# 
Csharp :: vb.net add row to datagridview programmatically 
Csharp :: c# template 
Csharp :: C# setting property values through reflection with attributes 
Csharp :: c# mongodb get all documents 
Csharp :: dictionary to list c# 
Csharp :: Read a Word Document Using C# 
Csharp :: rotate gameobject unity 
Csharp :: addd to array c# 
Csharp :: input unity 
Csharp :: c# remove duplicates from list 
Csharp :: how to add a force to an object unity 
Csharp :: What is the yield keyword used for in C#? 
Csharp :: string tochar array c# 
Csharp :: compact in laravrl 
Csharp :: c# remove the last character of a string 
Csharp :: how to make a 3d object do something when clicked on 
Csharp :: how to set the value of a textbox textmode=date asp.net c# 
Csharp :: c# split string by index 
Csharp :: #ifdef in c 
Csharp :: get device name c# console 
Csharp :: return an interface or a class C# 
Csharp :: Failed to generate swagger file. Error dotnet swagger tofile --serializeasv2 --output 
Csharp :: listbox items to string c# 
Csharp :: enum in c# 
Csharp :: viewBag as a list 
Csharp :: hide numericUpDown arrows 
Csharp :: c# get smallest of 3 numbers 
Csharp :: Remove access to admin from deleting the file in C# 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =