How to detect in Silverlight whether Network Connection is available?


In your Silverlight application, you might want to detect whether network connection is available and then based on the result, you might want to do a service call or disable few buttons. This is a most wanted feature by the Silverlight developers.

 

So if you are looking for code, this post will help you to understand the APIs and integrate the same in your Silverlight applications.

 

 

The abstract class “NetworkInterface” present in the “System.Net” assembly under the “System.Net.NetworkInformation” namespace provides you information related to network interface. This class exposes a method named “GetIsNetworkAvailable()” which returns boolean value based on the network availability.

 

Based on the returned value, you can easily do your stuffs like enabling/disabling buttons or do a service call. Here is the code snippet of the same stuff:

 

if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
    // do your stuffs when network available
}
else
{
    // do your stuffs when network is unavailable
    // here you might want to show a message to the user or just disable few buttons
}

 

 

If System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable() returns true, that means network is available; otherwise it will return false.

 

I hope that this small post will help you if you are looking for a code snippet to detect the network information in your Silverlight application. Stay tuned to my blog for articles, news and tips. Subscribe to the RSS feed and email newsletter to receive all the updates directly to your inbox. Also, connect with me on Twitter, Facebook and Google+ for technical updates and discussions. Thank you for visiting my site.


0 comments


 
© 2008-2014 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top