I want to invoke a function only if the device is connected to the system. So my problem is how can I check whether the device is connected or not through USB before invoking the function. Can anyone help...thanks in advance.
Asked
Active
Viewed 1,073 times
1
-
What system is it you're talking about? – Yngve B-Nilsen Feb 06 '12 at 12:19
-
1possible duplicate of [Detect if Windows Phone 7 is connected to desktop Zune software](http://stackoverflow.com/questions/4744399/detect-if-windows-phone-7-is-connected-to-desktop-zune-software) – ctacke Feb 06 '12 at 23:17
-
Perhaps this answer on a similar question might help you out: http://stackoverflow.com/a/4748481/880511 – Abbas Feb 06 '12 at 14:43
1 Answers
1
I think you should be able to find out by using the NetworkInterfaceInfo class:
var typ = NetworkInterface.NetworkInterfaceType;
if(typ == NetworkInterfaceType.Ethernet){
// do stuff
}
Note: If you disconnect your computer from the internet, I think this is no longer valid.. But as long as you're connected to a computer that is connected to a network and Zune is running, this should work (not tested)

Flexo
- 87,323
- 22
- 191
- 272

Yngve B-Nilsen
- 9,606
- 2
- 36
- 50
-
Hey i am not checking the network connection,i just want to check whether the phone is connected to my desktop or laptop through USB. – Rookie Feb 06 '12 at 12:39
-
This would require an established socket connection to an endpoint to work. – Magnus Johansson Feb 06 '12 at 13:23
-
-
@YngveB.Nilsen Hi, Thanks for your reply I guess it is working but I am still stuck at one thing 'var typ' is always set to 'NONE' whether I am connected to LAN cable or wireless internet or not connected to any internet at all(it should be 'Ethernet' if zune is connected in this case, correct me if I am wrong). Thanks in Advance. – Rookie Feb 07 '12 at 11:04