Solved

ApartmentState.STA or ApartmentState.MTA in .net

Posted on 2009-07-08
5
1,568 Views
Last Modified: 2012-05-07
i want to know which thread state is faster  ApartmentState.STA or ApartmentState.MTA in vb.net and why?
0
Comment
Question by:mrpatil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 250 total points
ID: 24816145
When it works, and doesn't require heavy extra coding, MTA:

"From COM's perspective, a multithreaded apartment (MTA) is an easier model compared to an STA. Incoming RPC calls directly use the thread assigned by the RPC run time. No message pump or hidden window is used for communication between the client and object. The object does not live in any specific thread. Within a process, clients from any thread can directly call any object inside the MTA. (There is only one MTA per process.) Interface pointers between threads do not need to be marshaled."

 ( quoted from http://msdn.microsoft.com/en-us/library/ms809311.aspx )

But, as the same source warns,

"However, an MTA requires extreme caution on the part of the object implementor. Multiple threads can call an object method at the same time. Therefore the object must provide synchronized access to any instance using synchronization primitives like events, mutexes, or semaphores. It must be completely thread safe and reentrant."
0
 

Author Comment

by:mrpatil
ID: 24822162
MTA is faster or STA
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 24822455
MTA - if it doesn't crash!
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 24822472
The same code will run faster in MTA than STA - but STA is safer.  

You might have to do extra coding in MTA to avoid threads stomping on each other.

0

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question