?
Solved

ApartmentState.STA or ApartmentState.MTA in .net

Posted on 2009-07-08
5
Medium Priority
?
1,573 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 1000 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

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

718 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