Subscribe to the RSS feed then follow me on twitter at @mrlacey (misc) and @wpug (WPDev news)

Tuesday, December 07, 2010

[WP7Dev] Gotchas when detecting network connectivity

When developing for an occassionaly connected device it's useful to know if there's a connection currently available.

The Windows Phone 7 SDK makes this very easy with the GetIsNetworkAvailable() method on the NetworkInterface class.

There are, however, two gotchas you need to be aware of when debugging.

1. If you call this method in code running in the emulator it will always return true.

2. If you call this method in code running on a tethered device (as you may have connected when debugging on a real device) it will always return true.

In both instances you'll need to code around the issue. (Or set break points and move the next/current executing line.)

You should also write code to handle the situation where a network connection is available but your specific web service/site isn't.

Hope this saves someone some head scratching.

Are you a Windows Phone developer? If so, you could be getting rewards for the apps you build and the success they achieve by joining Nokia's DVLUP program.

No comments:

Post a Comment