What is the best way to check for Internet connectivity using .NET?

后端 未结 27 2020
感动是毒
感动是毒 2020-11-22 07:41

What is the fastest and most efficient way to check for Internet connectivity in .NET?

27条回答
  •  清酒与你
    2020-11-22 08:29

    public static bool HasConnection()
    {
        try
        {
            System.Net.IPHostEntry i = System.Net.Dns.GetHostEntry("www.google.com");
            return true;
        }
        catch
        {
            return false;
        }
    }
    

    That works

提交回复
热议问题