What are STA And MTA in threading?

Answer Posted / kiran kumar reddy

The Thread will create and enter a multi threaded apartment.
The Thread will create and enter a Single threaded apartment.

An apartment is a logical container within a process for
objects sharing the same thread access requirements. All
objects in the same apartment can receive calls from any
thread in the apartment. The .NET Framework does not use
apartments, and managed objects are responsible for using
all shared resources in a thread-safe manner themselves.

Because COM classes use apartments, the common language
runtime needs to create and initialize an apartment when
calling a COM object in a COM interop situation. A managed
thread can create and enter a single-threaded apartment
(STA) that allows only one thread, or a multithreaded
apartment (MTA) that contains one or more threads. You can
control the type of apartment created by setting the
ApartmentState property of the thread to one of the values
of the ApartmentState enumeration. Because a given thread
can only initialize a COM apartment once, you cannot change
the apartment type after the first call to the unmanaged code.

Is This Answer Correct ?    13 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you create user defined data types in c#?

527


What are the different states of a thread?

533


What do you mean by shared assembly?

586


How long can a string be c#?

511


In .NET which is the smallest unit of execution?

641






What is garbage collection? How to force garbage collector to run?

498


Explain how is the dll hell problem solved in .net?

467


What is c# best for?

529


What's the difference between system.string and system.text.stringbuilder classes?

531


What is an assembly loader?

519


What’s a strong name?

527


What is difference between encapsulation and abstraction in c#?

462


If you donot specify an access modifier for a method, what is the default access modifier?

545


Why hashtable is thread safe in c#?

497


What are the basics of c#?

555