Advanced COM COMThread and COMApartment notes
There are some important rules that must be followed when using COMApartment and/or COMThread objects. While they are looking quite simple for use the developer needs to pay attention to some additional details.

Life cycle

The both objects maintain threads where other COM objects can be created. This is more important for the COMApartment object (usually no objects are created in the COMThread - instead they are only referred/called from it). So these objects created in the apartment can function correctly only while the corresponding COMApartment is alive.

Therefore if the COMApartment is destroyed (just released) before all the other objects in the apartment are released they will not be able to to exist nor uninitialize correctly. So the best way to deal with COMApartment is to keep it and all the objects created in it together. For example in Application variables.

Similar is the case with the COMThread and COMScriptThread objects. They must be in Active state as long as the currently executed call is in progress (do not call terminate unless there is some kind of fatal problem).

 

newObjects Copyright 2001-2006 newObjects [ ]