PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft C# .NET
difference between STA and MTA
Forums
Newsgroups
Microsoft DotNet
Microsoft C# .NET
difference between STA and MTA
![]() |
difference between STA and MTA |
|
|
Thread Tools |
Rating:
|
|
|
#21 |
|
Guest
Posts: n/a
|
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> > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 


