Re: Questions of apartment
nly <nlyee2001@yahoo.com> wrote:
1. "STA can only contain one thread. And there is also the old model
where it can only contain one thread but it also has to be the main
thread."
This is a pretty confusing statement, especially the second part. Where
did you get it from?
For details on OLE threading models, see
http://support.microsoft.com/kb/150777/
Is STA still used nowadays?
Yes.
Does it have to be in main thread like
old model of STA?
An application may create multiple STA threads, each hosted in its own
STA apartment. One of these threads is designated a main STA thread.
Certain legacy components (very rare nowadays) must be created on main
STA thread (COM usually takes care of this automatically). If you don't
have to deal with such legacy components, the notion of main STA thread
has no significance.
2. "Marshalling-unmarshalling is required only if the threads live in
incompatible apartments. For example a thread in MTA tries to access
an object in STA."
Isn't correct to say, instead, that Marshalling-unmarshalling is
always needed for passing values or pointer-to-interface across
boundary between apartments?
Yes. It's apartment boundary that's important: e.g. marshalling would
still be required for a call between two different STA apartments within
a single process.
3. Is it correct to say that proxy/stub objects needs to be created
only when Marshalling-unmarshalling needed?
Yes. In fact, you don't normally create them explicitly: COM creates
them for you automatically as part of marshalling process.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925