Does ActiveX control need thread synchronization?

I am currently developing a simple ActiveX control. This control provides a small set of properties and methods. It is not known now whether ActiveX methods will be called from different threads. To be prepared to consider this scenario, I decided to implement thread synchronization within each method that was detected by the control. Do I need to implement this synchronization or is it already implemented using the Microsoft ActiveX platform? Am I doing something extra?

+3
source share
1 answer

How this works depends on which streaming model your control uses, but assuming your ActiveX control uses the APARTMENT stream model (which is almost always necessary), you can assume that all methods in your ActiveX control will be called on the same thread. If other threads are accessing them, ActiveX will automatically redirect the call to the correct thread so that you receive it in that thread.

Similarly, you should never call an ActiveX object or COM interface that you use from a thread other than the one you received it on. If you need to make calls from multiple threads, there are ways to do this, but that is beyond the scope of this question.

. , , .

+1

Source: https://habr.com/ru/post/1786338/


All Articles