how to check InternetConnection in wp7?

让人想犯罪 __ 提交于 2019-12-08 15:58:25

问题


i want to check internet connection in my application.but, its not displaying properly.

i am using this code for internet connection:

 NetworkInterface.GetIsNetworkAvailable();

in this code always return true value.if net available or not available return true only.

if anyone know tell me idea to do this.

thanks.


回答1:


Check NetworkInterfaceType. If Internet is available then It should be other than None

 return (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType != 
 Microsoft.Phone.Net.NetworkInformation.NetworkInterfaceType.None);



回答2:


In the Windows Phone Emulator it's correct that NetworkInterface.GetIsNetworkAvailable() will always return true. Even if your PC has no internet connection, the emulator counts the local/internal connection to your PC.

The return value will be false if you test your application on a real device and switch it e.g. in flight-mode.




回答3:


Yes NetworkInterface.GetIsNetworkAvailable() will always return true on windows phone emulator you can try below code to detect network availability.

using Microsoft.Phone.Net.NetworkInformation;    
    if (DeviceNetworkInformation.IsNetworkAvailable)
    {
    MessageBox.Show("network available") ;              
    }
    else
    {
    MessageBox.Show("No network.") ;   
    }


来源:https://stackoverflow.com/questions/8341169/how-to-check-internetconnection-in-wp7

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