2
//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();
}
이것은 VC++에서 MFC를 사용하는 샘플 코드이며 작업자 스레드를 사용하여 작업을 완료하고 결과를 컨트롤에 보내려고합니다. 어느 것이 바람직하거나 다른 어떤 문제를 해결할 것입니까?MFC에서 작업자 스레드 사용
[MFC : 다른 스레드의 GUI에 액세스 할 수 있습니까?] (http://stackoverflow.com/questions/18462347/mfc-accessing-gui-from-another-thread) –
중복되지 않습니다. 이전의 스레드는 I에만 관련되었고 MFC GUI 스레드에서 작업 스레드의 사용을 금지한다는 권고가있었습니다. 사례 2의 쿼리는 비동기 우선 순위 대기열을 사용하여 상황에 대한 해결 방법을 탐색하고 주 GUI 스레드가 게시 메시지를 처리하도록 허용합니다. – seccpur