Windows Phone 7 development tips
Tag Archives: connection
2011/06/15Posted by on
Knowing the status of the device connection can be very useful, displaying an error when trying to access something on the internet when the device has no connection is good practice. This is one of the points Microsoft loves to look at, especially when selecting featured applications.
There are two ways to handle this :
First is to use NetworkChange class, for example, in your App.xaml.cs constructor :
// Standard App() content
NetworkChange.NetworkAddressChanged += new
void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
if (Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType ==
Or, check directly where you need to use the connection :
NetworkInterfaceType type = NetworkInterface.NetworkInterfaceType;
if (type == NetworkInterfaceType.None)
// Handle error
This can also be used to determine what connection type is being used, simply compare NetworkInterface.NetworkInterfaceType to the possible values of NetworkInterfaceType enum.
Be very careful when using this, as when in bad cellular cover, this call can take up to 20s.