public static bool IsNetworkAvailable()
{
bool isAvailable = false;
var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile == null) {
return false;
}
var connections = profile.GetNetworkConnectivityLevel();
switch (connections) {
case NetworkConnectivityLevel.ConstrainedInternetAccess:
case NetworkConnectivityLevel.InternetAccess:
isAvailable = true;
break;
case NetworkConnectivityLevel.LocalAccess:
case NetworkConnectivityLevel.None:
isAvailable = false;
break;
default:
break;
}
return isAvailable;
}
參考資料:
https://limzhenghong.wordpress.com/2013/10/26/checking-for-internet-connectivity-in-windows-8-cwinrt/
文章標籤
全站熱搜
