Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1585
  • Last Modified:

ApartmentState.STA or ApartmentState.MTA in .net

i want to know which thread state is faster  ApartmentState.STA or ApartmentState.MTA in vb.net and why?
0
mrpatil
Asked:
mrpatil
  • 3
1 Solution
 
Jens FiedererCommented:
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
 
mrpatilAuthor Commented:
MTA is faster or STA
0
 
Jens FiedererCommented:
MTA - if it doesn't crash!
0
 
Jens FiedererCommented:
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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now