Solved

ApartmentState.STA or ApartmentState.MTA in .net

Posted on 2009-07-08
5
1,558 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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