Solved

ApartmentState.STA or ApartmentState.MTA in .net

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now