How can I determine whether I am connected to WiFi or a cellular network wpf?

不打扰是莪最后的温柔 提交于 2019-12-13 02:24:42

问题


I am working with a WPF app for tablets with Windows 8.1. The app connects to SAP. In the settings I have to implement an option for synchronisation to only occur over a WiFi network.

How can I determine if the tablet is connected to WiFi or a cellular network? From my research I have found ways to do this on XP and Vista or using Universal Apps. How can I implement this feature using WPF and Windows 8.1?


回答1:


The following code should work, in c#

if(Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork) 

{
//Mobile Data
}

else if(Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)

{
//WiFi connection
}

else

{
//No network
}


来源:https://stackoverflow.com/questions/32501030/how-can-i-determine-whether-i-am-connected-to-wifi-or-a-cellular-network-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!