Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

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. - Article authored by Kunal Chowdhury on .

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.

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.