How can I create a COM+ single instance application?

Mar 30 2011 12:23 PM
I'm trying to create a COM+ application that has always only one instance in the whole operating system. I need it to link some other modules between them. But I've not succeeded to find such example, all examples I could find avoid such situation. I'm trying to use COMPlusCache example from codeproject.com for the base. It uses such attribute
[ObjectPooling(Enabled=true, MinPoolSize=1, MaxPoolSize=1, CreationTimeout=20000)]
But it uses just generic C# constructors without Component Service usage. That suits for only C# projects but I need to call it also from C++ and may be from some other plattforms. But when I'm trying to use Component Service the following way (for debugging purposes I use the same console application for several instances)
  object c = Activator.CreateInstance(Type.GetTypeFromProgID("Imutome.COMPlusCache.Cache"));
  c.GetType().InvokeMember("add_Transfering", BindingFlags.InvokeMethod, null, c, new object[] { new EventHandler(c_Transfering) });
  Console.ReadLine();
  object c2 = Activator.CreateInstance(Type.GetTypeFromProgID("Imutome.COMPlusCache.Cache"));
  c2.GetType().InvokeMember("OnTransfer", BindingFlags.InvokeMethod, null, c2, null);
I have such problem that the variable c2 doesn't get a reference to the same instance of the COM+ application but it just becomes to wait when the objects pool will become free. And I've not succeeded to find some information about what can I change to make it to get a reference to the same instance, but not to wait.

P. S. Automatically displayed possible solutions gave me an idea of some bypass but with memory overusage. So it can be some reserved way but it'll be better if I'll be able to have one instance of my COM+ application but not of some external module to prevent memory overusage.

Answers (2)