MFC C ++背景线程 [英] MFC C++ Background Thread

查看:291
本文介绍了MFC C ++背景线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个MFC(文档/视图)应用程序,我想让它在后台连续监听设备连接时,然后自动复制设备上的文件,而无需用户需要交互或暂停/打扰什么他们在做。



创建一个工作线程与拥有后台线程一样吗?



感谢,

解决方案

是的,它们作为一个普通的后台线程,你有一个函数获取参数,然后你可以进入你的监听器循环。我将这个函数放在单独的类中,也许是一个单例类的形式,这种方式你可以很容易地启动/停止你的设备监听器。如果你需要发送进度信息从这个工作线程到GUI,使用PostMessage到你的GUI窗口。



一如既往MSDN提供吨文档:
http://msdn.microsoft.com/en- us / library / 975t8ks0%28v = vs.80%29


I am making an MFC (document/view) application and I want it to constantly listen in the background for when a device is connected and then automatically copy the files on the device without the user needing to interact or pause/disturb what they are doing.

Is creating a worker thread the same as having a background thread? Would I create it as a function in the document file or as a separate class?

Thanks,

解决方案

Yes, they behave as a normal background threads, you have a function that gets parameter, and then you can enter your listener loop. I would put this function in separate class, maybe in a form of a singleton class, this way you can easily start/stop your device listener. If you would ever need to send information of progress from this worker thread to GUI, use PostMessage to you GUI windows.

as always MSDN provides tons of documentation: http://msdn.microsoft.com/en-us/library/975t8ks0%28v=vs.80%29

这篇关于MFC C ++背景线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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