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

153 views Asked by At

Ref: 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". This is not the case if the DLL is called in the UI thread. However, in my case, I have some pretty resource intensive calls, is there any way around this?

1

There are 1 answers

0
Jalal Said On

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. you can accomplish this by Implement ISynchonizeInvoke in the classes that communicating with the com, check this.