Re: Parent and Child in separate UI Threads

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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:


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
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: DLL and communication from another process exe
    ... It is risky to do cross-thread SendMessage, but if all you want is a bool, then if you are ... If I were doing this in a DLL, I might consider creating a UI thread in the DLL that ... creates an invisible window that handles the communication. ... EXE gets SendMessage from DLL ...
    (microsoft.public.vc.mfc)
  • Re: Overridden WndProc not working in some cases?
    ... Unmanaged C++ DLL ... separate thread) it seems to work fine and receives all messages. ... However if I do what I was doing before which is creating a window in ... For some reason the first message hits my app okay, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: recognize .Net controls properly and get infos/styles/properties
    ... and convert and compile the source in VS 2005 ... Since the error is not stopping the generation of the .exe and .dll I ... have both .net 1.0 and 2.0 window listed in the treeview. ...
    (microsoft.public.vc.language)
  • Re: Threading problem with Garbage Collector
    ... It itself controls calls to a DLL ... "A"), it loads the DLL, which in turn then creates a window (it needs to, ... Disposemethod it uses the label window to synchronize the FreeLibrary ... delegate void DelegateKillDLL(); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Simulating Control-Alt-Delete?
    ... Winlogon.exe window or not. ... all desktops and all top level windows. ... the WinLogon window didn't show. ... > Write this part of your test suite as a DLL, ...
    (microsoft.public.win32.programmer.kernel)