I have an STA thread in which I am currently executing some operation. Due to limitations of the environment (Office), there are certain things that I cannot do at this point in time. However, I can do these things immediately after the current message pump cycle is complete.
I would normally do this with my own message-only window handle to which I would post a message using PostMessage. However, given the environment and the architecture at hand, it is critical that the operation be queued alongside other COM object invocations coming from other threads/processes. Or in more exact terms, the post-invoke operations will need to be executed during a CoWaitForMultipleHandles call.
Does COM(+) provide a mechanism for invoking a method "later"? Other than:
- Create a thread myself (or otherwise reuse a thread I have created myself). Make it an STA thread. Marshal my object interface to that thread. Use ICallFactory to create a call object for my async interface. Fire and forget from this secondary thread.
- Create an MTA object strictly for the postback (the target COM server is still an STA object on the original STA thread). When instantiated, COM will create a thread for me. Call to that MTA object to schedule the postback (using the same ICallFactory method as before).
- Dig out the COM dispatcher window handle and PostMessage to it.
The first two require a separate thread, which seems undesirable. The last is a hack.