Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single-Threaded Apartments vs Multi-Threaded Apartments [duplicate]

Possible Duplicate:
Could you explain STA and MTA?

All ThreadPool threads are in the multithreaded apartment.

--As per the MSDN

What does that mean? I am really concerned with what the difference between the multi vs single threaded apartment model is. Or what does the apartment model mean? I have read the MSDN on it, and it doesn't really make sense to me. I think I may have an idea, but I was thinking someone on here could explain it in plain English.

Thanks, Anthony D

Update 1

Found this Could you explain STA and MTA?

Can anyone be more descriptive?

Update 2

I am also looking for an answer about how this applies to the thread pool, and what I need to watch out for because of this.

like image 992
Anthony D Avatar asked Jan 27 '09 20:01

Anthony D


People also ask

Is multi thread better than single thread?

Advantages of Multithreaded Processes All the threads of a process share its resources such as memory, data, files etc. A single application can have different threads within the same address space using resource sharing. It is more economical to use threads as they share the process resources.

What is multi threaded apartment?

In a multithreaded apartment model, all the threads in the process that have been initialized as free-threaded reside in a single apartment. Therefore, there is no need to marshal between threads. The threads need not retrieve and dispatch messages because COM does not use window messages in this model.

What is a single threaded apartment?

Single-threaded apartments consist of exactly one thread, so all COM objects that live in a single-threaded apartment can receive method calls only from the one thread that belongs to that apartment.

What does it mean to be single threaded?

the execution of an entire task from beginning to end without interruption.


1 Answers

STA (single-threaded apartment) and MTA (multi-threaded apartment) are to do with COM. COM components can be designed to be accessed by a single thread, in which case it they are hosted in an STA, or they can be made internally thread safe, and hosted in an MTA. A process can have only one MTA, but many STAs. If you're only going to consume COM components all that you really need to know is that you have to match the apartment to the component or nasty things will happen.

like image 61
Stu Mackellar Avatar answered Oct 02 '22 14:10

Stu Mackellar