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

查看:27
本文介绍了我需要一个事件来检测 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天全站免登陆