开发者

How to check if internet connection was lost WP7

How can I chec开发者_JS百科k if internet connection was lost in WP7.I'm developing social app and if internet connection was lost I have FileNotFoundException.I can't use try/catch because its doesn't prevent my app from closing with exception.Also if (NetworkInterface.GetIsNetworkAvailable()) works only from time to time and not always shows the truth.


The only reliable way I have found is to ping something reliable. My customer set up a "ping" call on the server that I need to access, which is the ultimate test. If I can reach that call, I can (or shoule be able to) reach any of them.


        bool isAvailable = NetworkInterface.GetIsNetworkAvailable();
        if (isAvailable == false)
        {
            //Logic here
        }
        else
        {
             //Code
        }

It works all the time for me...


NetworkInterface.GetIsNetworkAvailable() doesnt seem to work correctly all the time. Its better to use WebClient object to download some URL which you are sure is available always.


@Francesco : I think you are right, NetworkInterface.GetIsNetworkAvailable() works fine on phone, but its unreliable on emulator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜