Platform SDK: Transaction Server

Threading Issues

Calls into a resource dispenser may originate in one of the following threads:

If a resource dispenser is not a COM object, then it must be able to handle calls arriving from any thread at any time. If a resource dispenser is a COM object, then the COM object should be registered with a Threading Model of Both. This allows STA or MTA threads to create and use the resource dispenser without a thread switch.

If a resource dispenser creates and uses another COM object (for example, an out-of-process resource manager) then the resource dispenser may need to maintain multiple proxies to this other COM object, and ensure that calls to this other COM object are made using the appropriate proxy for the calling thread. When the resource dispenser creates this object, it marshals and saves the reference. Before calling the object again, it must unmarshal to create a proxy for the calling thread.

It may be more efficient to cache these per-thread proxies by keeping a map from the ThreadId to a proxy pointer. This map will continue to expand as new threads are used in the process.