Create a Windows Service application and either register your shared singleton object in ROT or simply use RegisterActiveObject
/RevokeActiveObject
to register it with a unique guid.
Accordingly, use ROT or GetActiveObject
to obtain a COM proxy to this object from any other place. You'd need to manually start the windows service if the object has not been registered.
Updated, it's also possible to implement IClassFactory
on the singleton object (which would return itself). The service would register the singleton via CoRegisterClassObject
, resembling the out-of-proc server behavior. The initial service activation would still be required.
Finally, perhaps the simplest solution is to register the assembly as an out-of-proc DLL surrogate. I haven't tried that, but it ought to be easy with [ComRegisterFunction]
/ [ComUnregisterFunction]
custom interop registration.
Updated, here is an example of using a surrogate process.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…