MFC C++ Background Thread(MFC C++ 后台线程)
问题描述
我正在制作一个 MFC(文档/视图)应用程序,我希望它在后台持续监听设备何时连接,然后自动复制设备上的文件,而无需用户交互或暂停/打扰什么他们在做.
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?
谢谢,
推荐答案
是的,它们就像一个普通的后台线程,你有一个获取参数的函数,然后你可以进入你的监听循环.我会把这个函数放在单独的类中,也许是单例类的形式,这样你就可以轻松地启动/停止你的设备监听器.如果您需要将此工作线程的进度信息发送到 GUI,请使用 PostMessage 到您的 GUI 窗口.
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.
MSDN 一如既往地提供大量文档:http://msdn.microsoft.com/en-us/library/975t8ks0%28v=vs.80%29
as always MSDN provides tons of documentation: http://msdn.microsoft.com/en-us/library/975t8ks0%28v=vs.80%29
这篇关于MFC C++ 后台线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MFC C++ 后台线程


基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30