获取 Windows 7 的网络状态 [英] Get Windows 7's network status
问题描述
在 Windows 7 中,每当互联网访问丢失时,网络指示灯会变为黄色.我想在我的软件中获得此状态并在互联网连接丢失时设置警报(互联网警报).我怎样才能获得这个状态?所有其他库,如这个,只显示断开连接的状态(红色),否则说互联网可用.我找不到任何执行此操作的库,也找不到任何 API 函数.
In Windows 7 whenever the internet access gets lost, the network indicator turns yellow. I want to get this status in my software and set an alarm whenever the internet connection gets lost (an internet alarm). How can I get this status? All of the other libraries like this one, just show the status of disconnection (red) and otherwise say that the internet is available. I couldn't find any library that does this nor any API function.
推荐答案
在 Windows API 代码包中 有一个 NetworkManager 类可以让你同时获取 IsConnected 和 IsConnectedToInternet.也带有一些有用的样本.如果您想检测状态变化,请不要轮询 - 您可以为 .NET 事件添加处理程序,就像添加点击处理程序一样.
In the Windows API Code Pack there is a NetworkManager class that gets you both IsConnected and IsConnectedToInternet. Comes with some useful samples too. If you want to detect a change in status, do not poll - there are .NET events you can add handlers for just like adding a click handler.
另见检测互联网 V. 本地局域网连接,一种优雅/简单的方式来检查互联网是否可用与否,我需要一个事件来检测互联网连接/断开等
这篇关于获取 Windows 7 的网络状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!