我如何检查网络连接?

我如何检查网络连接?

问题描述:

什么是确定是否有可用的网络连接的最佳方式?

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

您可以为您在.NET 2.0的网络连接使用GetIsNetworkAvailable()$c$c>:

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

System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()

要监视的IP地址或网络可用性的变化而变化使用事件从NetworkChange类:

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