Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Hour 16. Working with Data > Determining Network Connectivity

Determining Network Connectivity

If your application requires network connectivity in order to function properly or to provide a richer set of features, you must first determine if the hardware actually has an active network connection.

The Microsoft.Phone.Net.NetworkInformation namespace provides the classes necessary for determining network connectivity. Although the code to do this, shown in Listing 16.1, is relatively simple, it isn’t an instantaneous operation; therefore, you should do this in a background thread for performance.

Listing 16.1 Determining Network Availability


// Detecting the interface type may take a few seconds, so this should be done in
// a background thread.
ThreadPool.QueueUserWorkItem((obj) =>
{
   var networkType =
      Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType;
   Dispatcher.BeginInvoke(() =>
   {
     /*Set the current UI state based upon networkType */
   });
});


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint