Hello to everyone,
This thing is driving me crazy for the past days, so i would appreciate any insight.
Im writing an MFC dialogue application in VS2008.
In simple words im doing the following.
I have a function that is a member of the
*dlg class (lets call it
I have created a timer and an
MyAppDlg::onTimer() handler method that gets called whenever the timer ticks.
I have also created an MSMQ COM object and have registered its
"Arrived" event with the
MyAppDlg::newMessage() function. This function gets called when a new message arrives in the MSMQ queue.
Both these functions call the
If theres an error (e.g. no connectivity with the DB) the
PostMessageToDB() function pops an error message by calling the
AfxMessageBox( errorMsg, MB_RETRYCANCEL |MB_ICONERROR| MB_SYSTEMMODAL); method.
This method is modal. The execution of the
PostMessageToDB() function freezes and my application does not continue until the user hits the retry (or cancel) button.
So far so good.
BUT while waiting for a user response, if the timer ticks again or a new message arrives, my application gets woken up! The corresponding functions are called and it seems like a new "instance" of my program starts its execution flow. The result is to reach again at the same error and pop another error message.
How can this ever be possible?
Is anywhere there a hidden thread involved?
What will happen if i press the retry button while another "instance" of the above flow is on its way?
To what i know, the new event (timer tick or new message in the queue) shouldn't be dispatched before my application completes the processing of the previous message and returns. That's how the windows message loop works right?
I guess i miss the basics of the MFC architecture. If you know a link to a tutorial/article that can help me understand the above behavior i would be grateful!