views:

28

answers:

2

1) .NET Assembly MyAssembly.dll implements a Singleton class MyClass

2) A .NET APP has a reference to MyAssembly.dll and uses MyClass

3) A .NET ActiveX MyActiveX.dll implements a COM Visible class wich in turn references to MyClass in MyAssembly.dll

My question is: if the app and the ActiveX are running at the same time (the ActiveX in a web page), do I have one or two instances of MyAssembly.dll loaded? I need it to be one instance for the singleton to work.

Thanks

A: 

You are going to have two instances, they are running in different processes.

If you need to have a singleton that is accessed through an ActiveX control, I would suggest creating a WCF service to host your singleton object and provide access. You can then write a tiny COM-visible client that accesses the service to support your ActiveX control.

Guy Starbuck
Thank you both Stefan and Guy
Martín
A: 

The assembly is loaded into the Application Domain, static fields (where the singleton is based on) are instantiated per Application Domain. There is at least one App Domain per process, so you get at least one instance per process.

Your ActiveX component is instantiated in another process then the .NET Application. You don't get shared memory.

To instantiate the singleton only once, you need to start a single process and access it remotely. You could achieve this by the use of remoting, DCOM, WCF or something like this. You need to make sure that both process access the this instance.

Stefan Steinegger