Ian is right, MTA is not a superset of STA, and you better stay in STA for
UI threads. However, that doesn't stop you from creating new threads with
either MTA or STA modes (the attribute only applies to the mail thread,
subsequent threads choose their threading model through a property). So you
can have STA threads for UI stuff, and a bunch of MTA threads for whatever
thing you need to do in a MTA.

By the way, Ian: what did you mean by "MTA components will never be
reentered on a single thread, but STA components can be". AFAIK, MTA
components CAN reenter into themselves either directly or indirectly...

Regards,
Pablo Castro
Lagash Systems S.A.


----- Original Message -----
From: "Ian Griffiths" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, May 13, 2002 5:00 PM
Subject: Re: [ADVANCED-DOTNET] ApartmentStates: MTA, STA & Unknown


> Also, if you set it to MTAThread on a Windows Forms app, subtle things
start
> to go wrong.  For example, Drag and Drop stops working.  Why?  Well the
clue
> is in its full name: OLE Drag and Drop - it's an OLE thing, so it requires
> OleInitialize to be called. Calling OleInitialize means being on an STA.
>
> So even if you're not using COM interop, you still want to be on an STA in
a
> Windows Forms application.
>
>
> Also, the original author's statement:
>
> >>It seems to me that MTA is a superset of STA
>
> is not really accurate.  The MTA and the STA are wholly disjoint.  Calling
> from one to the other always involves going through a proxy and doing a
> thread switch.  So there are perf reasons for getting the right model.
And
> as it happens, components that work in the MTA don't necessarily work in
an
> STA - for example, you don't need to pump messages if you block
indefinitely
> in the MTA, but you do in an STA.  MTA components will never be reentered
on
> a single thread, but STA components can be.
>
>
> --
> Ian Griffiths
> DevelopMentor
>
> ----- Original Message -----
> From: "Marsh, Drew" <[EMAIL PROTECTED]>
>
>
> > Jonni Faiga [mailto:[EMAIL PROTECTED]] wrote:
> >
> > > Is the answer that MTA calling STA is not compatible and,
> > > since=20 most COM objects are STA, having [MTAThread] would
> > > cause COM to create a MTA compartment as a proxy to marshal
> > > calls to the COM STA?
> >
> > Because odds are today you're going to use a STA threaded COM component
> (or
> > ActiveX control) in that EXE. The VS.NET templates make this assumption
> and
> > play it on the safe side. If you're 100% positive you won't be using an
> STA
> > threaded component, go ahead and remove the attribute all together. Keep
> in
> > mind that most UI controls are apartment threaded and if you tried to
use
> > them without a message pump, then you're going to have problems. That
> said,
> > most of the time you can remove the attribute on console apps, but
rarely
> > can you remove it on a WinForms app.
>
> You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to