Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ActiveX control need thread synchronization?

I'm currently developing a simple ActiveX control. This control exposes a small set of properties and methods. It is not known now if the ActiveX methods will be called from different threads. In order to be ready to face this scenario I decided to implement a thread synchronization inside each methods exposed by the control. Do I need to implement this synchronization or it is already implemented by the Microsoft ActiveX framework? Am I doing something redundant?

like image 983
gionny Avatar asked Feb 17 '26 17:02

gionny


1 Answers

How this works depends on what threading model your control uses, but assuming your ActiveX control uses the "APARTMENT" threading model (which it nearly always should) you can assume that all methods on your ActiveX control will be called on the same thread. If other threads access them ActiveX will automatically marshall the call to the correct thread so that you receive it on that thread.

By the same token, you must never make calls on an ActiveX object or COM interface that you use from a thread other than the one you obtained it on. If you need to make calls from multiple threads there are ways of doing that, but that's outside of the scope of this question.

Summary: You don't have to worry about your methods being called from different threads, so you shouldn't need to worry about synchronization.

like image 120
taxilian Avatar answered Feb 19 '26 07:02

taxilian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!