Capturing network status change event(捕获网络状态变化事件)
问题描述
我正在尝试在 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.
这篇关于捕获网络状态变化事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:捕获网络状态变化事件
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- Windows Media Foundation 录制音频 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01