Detect network connectivity from a WPF/XBAP Application?
Someone asked on Stack Overflow:
Is there any way to determine if an XBAP (WPF hosted in a browser) application has network connectivity? If not, how would a traditional windows client written in C# and .NET determine if it has connectivity?
Basically the use case is an XBAP application running on a mobile laptop connected to an intranet via WiFi. The laptop will not have a connection to the Internet. The WiFi connection may or may not be there depending upon where the user is at the time.
I posted the following answer, which was chosen as the accepted answer and received 4 upvotes:
GateWayIPAddressInformation should work: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.gatewayipaddressinformation(loband).aspx
If you get the gateway IP address, and you can Ping (http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping(loband).aspx) it you are probably connected.
Originally posted on Stack Overflow — 4 upvotes (accepted answer). Licensed under CC BY-SA.