简体   繁体   English

如何在非UI线程中使用免注册COM?

[英]How can I use a reg-free COM in a non-UI thread?

Ref: https://connect.microsoft.com/VisualStudio/feedback/details/457217/reg-free-com-fails-when-threaded#tabs 参考: https : //connect.microsoft.com/VisualStudio/feedback/details/457217/reg-free-com-fails-when-threaded#tabs

When using a reg-free COM DLL (isolated = true) in a non-UI thread, I get "unable to cast COM object of type". 在非UI线程中使用无reg的COM DLL(isolated = true)时,出现“无法转换类型的COM对象”。 This is not the case if the DLL is called in the UI thread. 如果在UI线程中调用DLL,则不是这种情况。 However, in my case, I have some pretty resource intensive calls, is there any way around this? 但是,就我而言,我有一些非常耗费资源的电话,这有什么办法吗?

The best solution to get around this is by invoking the calls to the com in the main thread, even if you were on another method. 解决此问题的最佳解决方案是通过调用主线程中的com调用,即使您使用的是其他方法。 you can accomplish this by Implement ISynchonizeInvoke in the classes that communicating with the com, check this . 您可以通过在与com通信的类中实现ISynchonizeInvoke来实现此目的,请检查this

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

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