With regard to more than one UI thread per process...

I've managed to get some added information from the folks at Microsoft,
that I'd thought I'd share.  From a purely architectural point of view,
Windows supports any number of threads per process pumping windows
messages for the windows and controls created in their respective thread.

Microsoft advises against multiple UI threads per process for a variety of
reasons.  One being the complexity that's involved with managing the
independent window and control data on each thread and marshaling data
between them (if needed), synchronization, etc. From an implementation
stand-point, all the above isn't limiting, just *complex*.  Another, more
limiting reason Microsoft advises against more than one UI thread per
process is that there is a limit to five device contexts (DCs) that can be
actively written to.  This limitation is system-wide.  Adding another UI
thread to a process is defeating because the application would then be
able, and more likely, to have least two of these five DCs open for write
at a time (assuming two GUIs and they are visible at the same time).  When
there are five active DC writes, any additional writes are queued.  As far
as I know, it's impossible to know how many DCs are actively being written
to at a given time, so it would be impossible for application to
effectively synchronize access to methods that caused a DC write, if you
wanted to.  The impression I got was, given this almost "serial" nature of
control painting, it would actually be slower and more taxing (thread
context switching, thread stack, optional synchronization, etc) to have
more than one GUI thread per process.

Unlike VB6 and MFC, WinForms limits UI threads no more than the underlying
OS does.

The folks that have said Windows does not support more than one GUI thread
(or windows message pump, or windows message loop) per process have not
responded to me with a basis for these comments, so, I cannot include
their thoughts.  (possibly a hold-over from Win 3.1?).

As a side note, I'm looking to use up about 9 hours of free yearly
development advisory service from MS, if anyone has anything more on this
topic they would like answered (or any other topic you haven't had a
acceptable response on), that I can't answer, I can pass it along.

-- Peter
Microsoft MVP, Visual Developer - Visual C#
http://www.peterRitchie.com/blog/

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to