i have a COM object that i am using in dotnet and i have to call it always on the same thread. The issue is that conceptually it is being for multiple things throughout the program. What is the best way for ensuring that all uses of this object on called on this one specific background thread? Example code would be great.
Share
You could start a thread at program startup, which should handle all the COM interaction. Then you could have a wrapper object which pushes tasks onto a queue for the thread to handle.
The wrapper could contain synchronization code in order to hide the multi-threadedness to callers (ie. expose the wrapped calls as synchronous methods).
If this is a WinForms project, perhaps you could cut corners by simply using the GUI thread and the Control.Invoke method. (But if the calls take a long time, it is not a good idea, since you would be blocking the UI during the call).