MFC C++ Background Thread

老子叫甜甜 提交于 2019-12-20 04:33:15

问题


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,


回答1:


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



来源:https://stackoverflow.com/questions/12150596/mfc-c-background-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!