我需要一个事件来检测网络连接/断开事件、网络

2023-09-02 10:35:08 作者:▼ 羽化成烟

我们正在开发的.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得到这个工作的一些网址,因为它会增加相当大的性能开销。是否有任何.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?

有其示出了十字标志或当系统不conncected到互联网有限连接登入系统托盘的图标。这表明视窗知道,我想捕获该事件。

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.

推荐答案

这是全部覆盖(包括是在网络上,并具有网络之间的区别您连接到Internet)在的 http://msdn.microsoft.com/en-us/library/ee264321(VS.85)。 ASPX 。我希望你的意思是把你的帖子,Windows 7的标签,因为这一切都是pretty的新。

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()其pretty的多少做什么它在锡说。你必须跳了一下周围,以注册事件等。 $ C $信用证包装包装一些是为您和具有网络样本,你能适应。

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.