你能解释一下STA和MTA吗? [英] Could you explain STA and MTA?

查看:36
本文介绍了你能解释一下STA和MTA吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能用自己的话解释一下 STA 和 MTA 吗?

Can you explain STA and MTA in your own words?

此外,什么是单元线程,它们是否仅与 COM 有关?如果是,为什么?

Also, what are apartment threads and do they pertain only to COM? If so, why?

推荐答案

COM 线程模型称为单元"模型,其中初始化的 COM 对象的执行上下文与单个线程(单线程单元)或多线程(多线程单元).在此模型中,COM 对象一旦在单元中初始化,在其运行时期间就是该单元的一部分.

The COM threading model is called an "apartment" model, where the execution context of initialized COM objects is associated with either a single thread (Single Thread Apartment) or many threads (Multi Thread Apartment). In this model, a COM object, once initialized in an apartment, is part of that apartment for the duration of its runtime.

STA 模型用于非线程安全的 COM 对象.这意味着它们不处理自己的同步.它的一个常见用途是 UI 组件.因此,如果另一个线程需要与对象交互(例如按下表单中的按钮),则消息将被编组到 STA 线程上.windows窗体消息泵系统就是一个例子.

The STA model is used for COM objects that are not thread safe. That means they do not handle their own synchronization. A common use of this is a UI component. So if another thread needs to interact with the object (such as pushing a button in a form) then the message is marshalled onto the STA thread. The windows forms message pumping system is an example of this.

如果 COM 对象可以处理自己的同步,那么可以使用 MTA 模型,其中允许多个线程与对象交互,而无需编组调用.

If the COM object can handle its own synchronization then the MTA model can be used where multiple threads are allowed to interact with the object without marshalled calls.

这篇关于你能解释一下STA和MTA吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆