Re: multithreaded dialog application

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



See below....
On Fri, 29 Jun 2007 14:04:03 -0000, Ryan <ryan.martino@xxxxxxxxx> wrote:

My application is a dialog app, with one parent dialog with spawns
several (up to 20 or so) child dialogs. There are basically three
channels of input to the dialogs: user actions and messages that come
in on two seperate threads via socket connections. At this point, all
the socket messages are posted to the main thread to be processed.
Nearly all the socket messages are simply passed on to a child dialog
(or 3 or 4 in some instances) to be processed.

The number of messages received from the sockets can be quite large
and since they come in on two seperate threads, I think it would be
more efficient to handle these messages in multiple threads (this is a
realtime application so we want to reduce latency in processing
messages as much as possible). There is some calculation that is done
to process the various messages that could be pushed to a worker
thread, but nearly every message results in a UI update as well.
*****
Why not do the calculation in the receiving thread? The post to the window which is
supposed to receive the data, instead of the main window.

Note that "putting the dialogs in separate threads" will be an erroneous design; MFC (and
WIndows itself, for that matter) won't work well under that kind of scenario.

UI updates MUST be in the main GUI thread.

See my essay on the use of I/O Completion Ports to avoid message pump saturation by
PostMessage (it's on my MVP Tips site). I had to deal with exactly this problem, and that
is my solution.
******

My understanding is that there is no safe way to update the UI from
any threads other than the main thread. I'd like to know if this is
correct.
****
Yes
****
It's not clear from what I read, but I'm hoping it may be
possible to create child dialogs in a seperate UI thread.
****
No
****
If this
could be done for even one dialog, I believe we would derive
significant benefit from this. My concern is in still being able to
link the child dialog back to the parent dialog if they are in
seperate threads.
*****
And that's the problem, so it won't work. Don't even try. You would be doomed.
*****

Can anyone give some advice on what possible options I have or if I am
really stuck posting everything to the main thread?

Thanks,
Ryan
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.


Quantcast