问题描述
你好,
我正在寻求一些建议.我正在开发在具有WiFi功能的Windows 7平板电脑上运行的应用程序.建立互联网连接后,我需要上传数据.
我想知道建立互联网连接时是否有触发函数调用的方法.到目前为止,我唯一的想法是一个后台线程,该线程以设置的时间间隔ping一个网址,并在建立连接时对我的地址进行处理,但这似乎有点浪费,因为可能需要数小时才能再次建立Internet连接.
我想知道是否有人可以引导我寻求更优雅的解决方案?
谢谢
Hello,
I''m after some advise. I''m developing an application that runs on a windows 7 tablet with WiFi capabilities. I need to upload data when an internet connection is established.
I''m wondering if there is a method of firing a function call when an internet connection is established. The only idea I have had so far is a background thread which pings a web address at set intervals and when it makes a connection do my processing but this seems a little wasteful as it could be hours before an internet connection is established again.
I was wondering if anyone can direct me towards a more elegant solution?
Thanks
推荐答案
[DllImport("wininet.dll", SetLastError = true)]
static extern bool InternetCheckConnection(string lpszUrl, int dwFlags, int dwReserved);
http://msdn.microsoft.com/zh-我们/library/windows/desktop/aa384346%28v=vs.85%29.aspx [ ^ ]
易于尝试,也许对您有用.
第二个想法可以是检查用户是否启动了浏览器.例如,如果执行了Process Firefox或ie,或者您非常清楚地知道该进程是在连接上执行的(可能证明是Windows服务),请开始上传.
第三个想法可能是使用一种符合wifi wlanapi.dll中您的要求的方法.
问候
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384346%28v=vs.85%29.aspx[^]
Easy to try, maybe it''s working for you.
A second idea could be to check if user has started his browser. Something like if Process Firefox or ie is executed, or a process you pretty surly know that''s executed on connection (maybe proof as a windows service), begin your uploading.
A third idea could be using a method that matches your requirements from the wifi wlanapi.dll.
Regards
这篇关于建立了Internet连接侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!