捕获网络状态变化事件 [英] Capturing network status change event

查看:30
本文介绍了捕获网络状态变化事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 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.

这篇关于捕获网络状态变化事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆