开发者

How to check if internet connection is available in Silverlight OOB

开发者 https://www.devze.com 2023-01-26 19:15 出处:网络
I have a Silverlight 4 app that runs out of the browser, it also has a web service that it talks to for specific functionality.

I have a Silverlight 4 app that runs out of the browser, it also has a web service that it talks to for specific functionality.

I am trying开发者_如何学编程 to figure out how to check to see if the web service is available because the app is crashing when there is a break in internet connectivity.


The simplest answer is to make a request to the web service! Anything else you do will tell you if you can talk to some particular host or other, but that's not really what you care about... you care about whether or not you can talk to that particular web service. The web service being down is equivalent to the internet being down, as far as your app is concerned.

Find a cheap and harmless request you can make as a test call, and use that. Of course, just because you have a connection now doesn't mean you'll have one in a couple of minutes... so you should still make sure that your app doesn't actually crash when the connection goes away. That should actually be your first priority IMO: making it fail gracefully.


I found following solution

NetworkChange.NetworkAddressChanged += (sender, e) =>
{
   if (NetworkInterface.GetIsNetworkAvailable())
   {
       // network available
   }
   else
   {  
       // network is not available
   }
}

proof link

0

精彩评论

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

关注公众号