views:

122

answers:

2

Is there an easier fast way to detect whether the (Windows Phone 7) device has an internet connection.

I'm currently sending a web request, waiting the timeout period and handling the exception. Hoping for a quick easy way to query the device to see whether it has a connection before sending any requests...

Thanks in advance,

+2  A: 

There isn't really a faster way, though instead of a dummy request for this, perhaps you could actually make the request for data that you want, so if it does come back, you can handle the data without making a 2nd request.

Jeff Wilcox
This is what I'm doing now, I'm not using a dummy request. I'm really looking for a fast way to determine network connectivity WITHOUT making a request. But thanks for the reply...
will
+4  A: 

Hi Will,

This method will return NetworkInterfaceType.None if there is no connection.

NetworkInterface.GetInternetInterfaceType

Alternatively you will get NetworkInterfaceType.MobileBroadbandGSM, NetworkInterfaceType.Wireless80211, etc if there is a connection.

Mick N
So I can't seem to find that class in the latest Windows Phone SDK (the latest release). The namespace Microsoft.Devices.NetworkInformation doesn't exist in System.Devices.dll. Are you using the latest SDK? Thanks,
will
Nevermind, I found it (the docs are out of date). And looks like they simplified the interface a little. Now you can just call: System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable().
will
You can call that, however the historical observation has been that it's always returning the same result on the emulator regardless of connection status. GetInternetInterfaceType has been the way around this.
Mick N
Yes, just found that out. ;> Thanks again for the pointer.
will
yw :) /15char..
Mick N
I need the exact same thing, but on a PC, not on a phone... Unfortunately this method only exists on WP7. Do you know a way to do the same on Windows ?
Thomas Levesque