【发布时间】:2016-08-26 06:49:14
【问题描述】:
//Case I : ( It works but not sure if it is safe . Is it because the windows
messages are handle in a process queue already? )
void MyDlg::OnClickButton1()
{
std::thread([]()
{
// some long computation here
SetDlgItemText(IDC_STATIC_TEXT, L"Updated");
}).detach();
}
//Case II : ( It works . But is the process_queue redundant )
void MyDlg::OnClickButton1()
{
std::thread([]()
{
// some long computation here
command_node node =
command_factory("SetDlgItemText",IDC_STATIC_TEXT, "Updated");
SendMessageToMyProcessQueue(node);
}).detach();
}
void MyDlg::OnPaint()
{
ExecuteFromMyProcessQueue();
CDialogEx::OnPaint();
}
这是一个使用 MFC 的 VC++ 中的示例 sn-p,我想使用工作线程来完成任务并将结果发送到控件。哪个是可取的或任何其他解决方法?
【问题讨论】:
-
不重复。较早的线程只关注案例 I,建议禁止在 MFC GUI 线程中使用工作线程。我的查询案例 II 尝试通过使用异步优先级队列并允许主 GUI 线程处理发布消息来探索解决该情况的方法
标签: c++ multithreading visual-c++