捕获网络状态变化事件
我正在尝试在 Internet 连接丢失后重新建立时获取事件.它适用于我正在开发的数据传输软件.如果我在数据传输过程中丢失了网络,我希望在它恢复时收到通知并自动继续传输.
I am trying to get events when the internet connection is reestablished after it is lost. It is for a data transfer software that I am developing. If I lose the network during data transfer, I would like to be notified when it is back and continue the transfer automatically.
我当然可以创建一个单独的线程并使用计时器不时检查网络,但也许有更好的选择.
I can of course create a separate thread and check the network once in a while with a timer, but maybe there is a better option out there.
我主要在 C++(不是 .net)中为 Windows 开发.
I am developing for windows mainly, in C++ (not .net).
我也可以使用 wxwidgets(我将它用于 GUI),但我怀疑它是否提供任何相关功能.
I can also use wxwidgets (I use it for GUI) but I doubt it offers any related functionality.
推荐答案
您可能需要查看系统事件通知服务器 (SENS) API http://msdn.microsoft.com/en-us/library/cc185680(VS.85).aspx
You might want to check out the System Event Notification Server (SENS) API http://msdn.microsoft.com/en-us/library/cc185680(VS.85).aspx
我并没有真正使用过它,但它似乎提供了您正在寻找的事件.
I have not actually used it, but it seems like it supplies the events your looking for.
WMI 似乎拥有您需要的有关各种网络连接和状态更改的所有信息.它还具有可用于获取通知的异步事件模型.我想,诀窍是生成正确的 WMI 查询以获取您想要的信息.这 blog 看起来是正确的查询类型,而这个 MSDN 解释了如何异步处理事件.
WMI appears to have all the information you need about various network connectivity and state changes. It also has an asynchronous event model that can be used to get notifications. The trick is, i suppose, generating the proper WMI query to get the information you want. This blog looks like the right type of query, and this MSDN explains how to handle the events asynchronously.
相关文章