简体   繁体   English

在从STAThread实例调用的类上创建线程时,单元状态将是什么?

[英]When creating a Thread on a class called from an STAThread instance, what will the apartment state be?

I have project A and project B. Project B has a thread that does some work with Microsoft Outlook Interop. 我有项目A和项目B。项目B有一个与Microsoft Outlook Interop一起工作的线程。 Project A is a GUI and is marked as STAThread on the main entry point. 项目A是一个GUI,在主入口点上标记为STAThread。

If I call project b from within A, will the thread created in project B be STA or MTA? 如果我从A内调用项目b,那么在项目B中创建的线程是STA还是MTA?

I have an error "Retrieving the COM class factory for component with CLSID... An outgoing call cannot be made since the application is dispatching an input-sync call." 我遇到一个错误“正在使用CLSID检索组件的COM类工厂...由于应用程序正在调度输入同步调用,因此无法进行传出调用。”

All threads default to MTAs, unless SetApartmentState is called before the thread is started. 除非在启动线程之前调用SetApartmentState ,否则所有线程默认为MTA。

If you think about it, the thread can't share the Single Threaded Apartment of an existing thread. 如果你想想看,线程不能共享现有线程的单线程单元。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM