It is always better to detect the network connectivity and network type before performing any task on mobile devices. You can use GSM/EDGE/CDMA network for normal login functionality, updating status messages or perform normal task which doesn’t require huge bandwidth. Whereas, you can rely on WiFi or Ethernet (USB Connection) for synchronizing huge data like pictures, videos or audio files.
For checking network and its type, Windows Phone 7 consists two assemblies/namespaces.
System.Net.NetworkInformation
Microsoft.Phone.Net.NetworkInformation
However, you should use the second one (Microsoft.Phone.Net.NetworkInformation) for performing the tasks on devices. You can enumerate through network like:
1: switch (NetworkInterface.NetworkInterfaceType)
2: {3: case NetworkInterfaceType.Ethernet:
4: //Do something when Ethernet or
5: //USB connectivity is available
6: break;
7: case NetworkInterfaceType.MobileBroadbandCdma:
8: //Do something when CDMA network
9: //is available
10: break;
11: case NetworkInterfaceType.MobileBroadbandGsm:
12: //Do something when CDMA
13: //network is available
14: break;
15: case NetworkInterfaceType.None:
16: //The is no network
17: break;
18: case NetworkInterfaceType.Unknown:
19: //Connected network type is unknown
20: break;
21: case NetworkInterfaceType.Wireless80211:
22: //When device is connected to WiFi
23: break;
24: default:
25: break;
26: }Using this code you can execute your code depending on network interface type.
Find related post on MSDN: Click here
Namaste
Mayur Tendulkar | www.mayurtendulkar.com