Check internet connection (availability) in Windows 8

后端 未结 3 1816
天命终不由人
天命终不由人 2020-12-06 01:19

How to check internet connection availability in Windows 8,C# development ? I looked at MSDN but page has been deleted.

3条回答
  •  Happy的楠姐
    2020-12-06 01:38

    I use this snippet without problems:

    public static bool IsInternet()
    {
        ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
        bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
        return internet;
    }
    

提交回复
热议问题