


















To check for a network connection in .NET 2.0 use this:
System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()
To monitor a change in IP address or a change in network availability, use the events from the NetworkChange class:
System.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChangedSystem.Net.NetworkInformation.NetworkChange.NetworkAddressChanged
Or
try
{
System.Net.IPHostEntry objIPHE = System.Net.Dns.GetHostEntry("www.google.com");
}
catch
{
MessageBox.Show ("...No Conn...");
}
or
---------
bool ConnectionExists()
{
try
{
System.Net.Sockets.TcpClient clnt=new System.Net.Sockets.TcpClient("www.google.com",80);
clnt.Close();
return true;
}
catch(System.Exception ex)
{
return false;
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。