Re: Parent and Child in separate UI Threads
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 27 May 2008 13:37:00 -0400
The design failure is putting complex business logic in the main GUI thread. This is what
you need to fix, and the correct fix is NOT to put the window in a separate thread! The
solution is to move the business logic to a separate thread and have it tell the window
that the DLL manages, which is running in the UI thread, when there is something to
display.
Bad design cannot be compensated for by more bad design.
joe
On Tue, 27 May 2008 08:19:02 -0700, Denis Adamchuk
<DenisAdamchuk@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
"Ajay Kalra" wrote:Joseph M. Newcomer [MVP]
Well, we have an EXE module and DLL module.
EXE is an MDI MFC application and it uses Doc/View architecture.
DLL contains business logic, some MFC windows and some dialogs.
EXE collaborates with DLL via interface described by IDL (but it is not COM).
So one of the views in EXE is a parent of windows from DLL. The view is like
a container.
The goal is to make all DLL stuff to work in a separate thread.
Why? The scenario you described is nothing strange. Its common to have
MFC windows in a DLL. Why do you need a separate thread?
We have a lot of business logic inside of DLL and some operations are long.
Currently DLL code is not thread-safe at all so we have to make one
thread and execute all DLL stuff here. Making DLL code thread-safe is a
several years task.
It will have a message-only window that will receive messages from the main
thread (IDL wrapped calls) and place them to the DLL's thread message queue...
Why do you have a message queue related to a DLL? Whats the purpose of
it?
Now we have EXE and DLL collaborating via IDL. All calls are simply virtual
functions.
When DLL will be in another thread we are going to add a layer between EXE
and DLL for marshalling all calls. It will use SendMessage/PostMessage
depending to the function we need to call in DLL (blocking or unblocking).
These messages will be handled by window proc of a message-only window inside
the DLL in the separate thread.
So if we have unblocking operation the sequence is the following:
1) EXE calls Marshaller::SomeLongOperation()
2) Marshaller posts a message, say, ID_SOMELONGOPERATION to DLL's window
It allows EXE code to continue executing in the main thread while long
operation is executing in the separate thread.
Thanks
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Re: Parent and Child in separate UI Threads
- From: Ajay Kalra
- Re: Parent and Child in separate UI Threads
- From: Ajay Kalra
- Re: Parent and Child in separate UI Threads
- Prev by Date: Re: Parent and Child in separate UI Threads
- Next by Date: Re: Looking for ListCtrl/ListView with multiple large icon states
- Previous by thread: Re: Parent and Child in separate UI Threads
- Next by thread: Re: Parent and Child in separate UI Threads
- Index(es):
Relevant Pages
|