Word and IOleContainer.LockContainer
I am developing an OLE link source in C# and I am having trouble determining when to automatically exit when it runs as a hidden out-of-process server. Based on the documentation I would expect to exit when the IOleContainer.LockContainer() count reaches zero. Unfortunately Word 2000 and 2002 (but not 2007) calls LockContainer(false) while it still has IOleObject.Advise() and IDataObject.DAdvise() sinks registered with my application, which it is still trying to use. Therefore I cannot use LockContainer() as the signal to shut down my hidden out-of-process COM server. How should I decide when to shut down?
(I tried waiting until all advise connections were closed, but that means my application closes and re-opens for each linked object in the Word document. I tried adding a delay before shutdown to address this problem, but Word then stopped calling LockContainer(false) as before, leaving me with a positive lock count!)
(I tried waiting until all advise connections were closed, but that means my application closes and re-opens for each linked object in the Word document. I tried adding a delay before shutdown to address this problem, but Word then stopped calling LockContainer(false) as before, leaving me with a positive lock count!)