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.

Related Posts:

  • [WP7Dev] What do developers still want?The RTM version of the Windows Phone 7 development tools are now available for download. But what do the people who are using them think is still miss… Read More
  • Polling is a smelly anti-pattern! As someone who reads my blog I'm sure you're well aware of good practices around mobile development so this won't come as a surprise to you. In … Read More
  • [WP7Dev] Windows Phone 7 booksUPDATED: 21-July-2010 There are a number of books about Windows Phone 7 development, currently being written, that I am aware of. They are: "Program… Read More
  • Thank you NEBytesYesterday I went up to NEBytes to talk about Windows Phone 7 development. (Were you expecting me to talk about something else?) I had a really great … Read More
  • 4 touch points!Just wanted to clarify something for a few people. The Windows Phone 7 hardware specs state a MINIMUM of 4 concurrent multi-touch points. This is not… Read More

0 comments:

Post a Comment

I get a lot of comment spam :( - moderation may take a while.