Skip Navigation LinksHome / Tips / View Tip

Detecting Network Change in Silverllight 3 Application

+ Add to SilverlightShow Favorites
1 comments   /   posted by Nikolay Raychev on Mar 19, 2009
(2 votes)
Categories: Connectivity

In Silverlight 3 you are able to check if an internet connection is present. You can also detect network changes.

See also:
Silverlight 3 as a Desktop Application (Out-of-Browser Applications)

Network availability checking:

if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())  
{  
    this.InitTasks();  

Network change detection:

NetworkChange.NetworkAddressChanged += new 
NetworkAddressChangedEventHandler(NetworkChangedCallback); 

 

private void NetworkChangedCallback(object sender, EventArgs e)  
{  
    if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())  
    {  
        this.InitTasks();  
    }  

Demo

As an example I created the following demo:


This is a simple tasks list. You can add or delete tasks. The tasks are saved on the server and the application is using WCF Service to connect to the server. Nothing special. But if you save the application for offline use you can use it even if you don't have internet connection. I'm using the isolated storage to keep copy of the data on the client and the application is working with the local copy when there is no connection. It synchronizes automatically whenever the connection comes back.

Download Source 

 

Share


Comments

Comments RSS RSS
  • RE: Detecting Network Change in Silverllight 3 Application  

    posted by Peter Gfader on May 03, 2009 05:30
    nice demo!

Add Comment

 
 

   
  
  
   
Please add 3 and 2 and type the answer here: