我需要一个事件来检测Internet连接/断开连接 [英] I need a event to detect Internet connect/disconnect

查看:226
本文介绍了我需要一个事件来检测Internet连接/断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个.NET应用程序,其中一个要求是监控系统是否连接到互联网。

We are developing a .NET application where one of the requirements is to monitor whether the system is connected to the internet or not.

我们能够获得以太网电缆断开连接的.NET事件,但是如果调制解调器重置,则此事件不会触发。我不想继续ping一些URL来完成这项工作,因为它会增加可观的性能开销。有没有可以检查系统是否连接到互联网的.NET事件?

We were able to get a .NET event for "ethernet cable disconnect", but if the modem is reset then this event does not get triggered. I don't want to keep pinging some URL to get this done since it will add considerable performance overhead. Is there any .NET event which can check whether the system is connected to the internet or not?

系统托盘中有一个图标,显示交叉路口或有限的连接当系统不连接到互联网时签署。这意味着Windows知道,我想陷阱这个事件。

There is an icon in system tray which shows a cross sign or limited connectivity sign when the system is not conncected to the internet. That suggests Windows knows, and I want to trap that event.

推荐答案

这一切都包括在内(包括在网络并让网络连接到互联网) http: //msdn.microsoft.com/en-us/library/ee264321(VS.85).aspx 。我希望你的意思是将Windows 7标签放在你的帖子上,因为这一切都是新的。

This is all covered (including the difference between being on the network and having the network connect you to the Internet) at http://msdn.microsoft.com/en-us/library/ee264321(VS.85).aspx. I hope you meant to put that Windows 7 tag on your post, because all this is pretty new.

关键是 INetworkListManager.get_IsConnectedToInternet()这几乎是在锡上说的。您必须跳过一点才能注册活动等。代码包包装了一些为您提供网络样本,您可以适应。

The key is INetworkListManager.get_IsConnectedToInternet() which pretty much does what it says on the tin. You have to jump around a bit to register for the events etc. The Code Pack wraps some of that up for you and has a network sample you can adapt.

这篇关于我需要一个事件来检测Internet连接/断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆