惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
月光博客
月光博客
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
U
Unit 42
腾讯CDC
爱范儿
爱范儿
J
Java Code Geeks
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
B
Blog
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - 李昀璟

Export to Excel, Word with css (Cascading Style Sheets) Unit Tests for ASP.NET MVC application that uses resources in code behind. IIS 不能运行asp.net Useful Expressions - Business Correspondence How to Plan a Meeting Useful Expressions for Business Interaction Useful Expressions for Business Language 使用IP或机器名而不是localhost访问DotNetNuke DotNetNuke升级中遇到的问题 DNN端口的问题 升级DotNetNuke DotNetNuke的升级路径 设置为自动启动的WindowService没有开机启动 C# WinForm 边框阴影窗体 PostSubmitter~在WEB应用程序以外的其他程序里提交Web请求的类 Asp.Net部署问题 MSDTC的折磨 - 李昀璟 - 博客园 常用缩写 日本語文法勉強
检测是否连网
李昀璟 · 2012-01-03 · via 博客园 - 李昀璟

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.NetworkAvailabilityChanged

System.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;
}

}