PC Review Forums Newsgroups Microsoft DotNet Microsoft C# .NET difference between STA and MTA

Reply

difference between STA and MTA

 
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.
Old 30-01-2005, 04:42 AM   #21
cody
Guest
 
Posts: n/a
Default Re: difference between STA and MTA


What if I omit the XXXThread attribute? Then I cannot use COM controls but I
can use normal windows controls?
When is CoInitialize() called if I use COM? Is it called in the initializing
code of the XXXThread attribute? And when is CoUninitialize called?

"Richard Blewett [DevelopMentor]" <richardb@NOSPAMdevelop.com> schrieb im
Newsbeitrag news:ujdljab%23EHA.2272@TK2MSFTNGP10.phx.gbl...
> So the crucial thing is which apartment type should you choose for your
> code.
>
> If you are doing Windows Forms programming *always* mark the main thread
> with the STAThread attribute. Some controls are wrappers around ActiveX
> controls and so COM interop with be being used. ActiveX controls are all
> STA based and IIRC don't support being hosted from an MTA thread.
>
> Any other project you can omit the attribute unless it performs COM
> interop where you should really take control of your thread's apartment
> state. You want to make sure the thread enters the same typoe of apartment
> as the COMM object it is calling. There is a 1000 fold performance penalty
> for calling cross apartment compared with intra apartment calls
>
> Regards
>
> Richard Blewett - DevelopMentor
> http://www.dotnetconsult.co.uk/weblog
> http://www.dotnetconsult.co.uk
>
> As Richard said, STA's and MTA's are artifacts of COM. <snip: Joakim's
> excellent description of apartments omitted from brevity>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off