How do I check for a network connection?

c#, networking

Solution

You can check for a network connection in .NET 2.0 using `GetIsNetworkAvailable()`:

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

To monitor changes in IP address or changes in network availability use the events from the NetworkChange class:

System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged
System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged

Problem

What is the best way to determine if there is a network connection available?

Original source

Related problems