First let me say that I have roughly searched stackoverflow for this, but couldn't find a specific answer.
My question is rather theoretical and there is no problem with the running of any code. Please consider a simple MFC application with a timer event and a button (attached to an OnClick event).
void SampleDlg::OnTimer(UINT_PTR nIDEvent)
{
CString msg;
msg.Format("time: %lld, tid: %d", (int64_t)time(0), GetCurrentThreadId());
SetWindowText(msg);
}
My intuition suggests that if I sleep inside the OnClick event, main UI thread should hang and timer events shouldn't kick in.
void SampleDlg::OnClick()
{
Sleep(10000);
}
That is fine, however if I show a new modal dialog inside the OnClick, the timer events still happen. What is different here?
void SampleDlg::OnClick()
{
CString msg;
msg.Format("tid: %d is waiting...", GetCurrentThreadId());
::MessageBox(GetSafeHwnd(), msg, "Msg", 0);
// at this point msgbox tells us that thread with tid is waiting
// thread with tid wont reach this line until msgbox is closed
}
Edit: I have included GetCurrentThreadId()
calls to make what i want to ask more clear.
When I run the code above, both msgbox and the window title gives me the same thread-id: 22012 (for example). My question is, what is the value of PC/IP (program counter or instruction pointer) of thread 22012 when msgbox is being shown?