Hello,

I’m developing an application composed of three threads:
- The “main” thread, with the user interface and other stuff.
- A “working” thread that handles messages to perform actions.
- A “monitoring” thread that is used to load / unload monitoring panels.

The “main” thread starts both “working” and “monitoring” threads.

The user can ask to open/close monitoring panels, so the “main” thread posts messages to the “monitoring” thread. When a panel is opened or closed, it registers/unregisters itself to the “working” thread for notifications about the performed actions.

When the application is closed, the “main” thread stops the “monitoring” and the “working” threads by posting messages.

In normal processing, every thing works fine.


My problem is the following:

When a message is posted to the “monitoring” thread during a panel creation (panels are modless CDialog), the “monitoring” thread blocks on the Create(IDD); of the CDialog. More precisely in dlgcore.cpp, in method:
BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd, HINSTANCE hInst)
on line:
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate, pParentWnd->GetSafeHwnd(), AfxDlgProc);

This problem is very easy to reproduce if I use following code:
::PostThreadMessage ( monitoringThreadId, MSG_OpenPanel, 0, 0 );
::PostThreadMessage ( monitoringThreadId, MSG_ClosePanel, 0, 0 );

In my log I can see the both post message. Only the first one handled and its processing stay blocked on the CDialog Create(IDD) method, as explained above.

Thanks for your help.