When I run this code, the text is updated AFTER the message box in the thread is popped.
void PnlOptions::ClickHandler() {
SetWindowText(txt_progress_, "CLASS MEMBER FUNCTION");
HANDLE hThread = (HANDLE) _beginthreadex(0, 0, &ThreadProcess, 0, CREATE_SUSPENDED, 0);
ResumeThread(hThread);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
unsigned int __stdcall ThreadProcess(void * data0) {
MessageBox(NULL, "THREAD FREE FUNCTION", "Alert", MB_OK);
}
I thought it was because
If the thread is created in a runnable state (that is, if the CREATE_SUSPENDED flag is not used), the thread can start running before CreateThread returns and, in particular, before the caller receives the handle and identifier of the created thread.
but using a non-suspended thread: same result.
Also tried:
Using
CreateThread
Changing thread priority
Using
SendMessage
instead ofSetWindowText
PeekMessage
Why does the thread start before the UI is updated?
Declarations:
pnl_options.h:
unsigned int __stdcall ThreadProcess(void *);
public PnlOptions:
void Init(HWND);
void ClickHandler();
private:
HWND txt_progress_;
pnl_options.cpp (other than above code):
void PnlOptions::Init(HWND hwnd0) {
txt_progress_ = CreateWindowEx (0,
TEXT("EDIT"), "Press \"GO\" to process all selected files.",
SS_LEFT | SS_CENTERIMAGE | WS_VISIBLE | WS_CHILD,
0, 0, 0, 0,
hwnd0, (HMENU) IDT_PROGRESSTEXT, NULL, NULL
);
}