1

Imagine this simple scenario:

I created a Class-Library DLL in .NET, which has 1 class, and this class has 2 fields(with matching Get+Set Properties): - int A - int B

Now I create an Executable, called Program1, which references that DLL, and instantiates the mentioned class, and I also create a second Executable, called Program2, which references that DLL too, and instantiates the mentioned class too.

In this way, I have 2 programs: Program1 and Program2, and both will create a seperate instance of the class in the DLL.

But what If I want Program1 and Program2 to talk to 1 shared instance of that class?

How do I do it?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Omer
  • 91
  • 2
  • 9
  • Or [Sharing dll's between processes - virtual memory doesn't seem to benefit](http://stackoverflow.com/questions/6473496/sharing-dlls-between-processes-virtual-memory-doesnt-seem-to-benefit), [Share DLL between 2 process in .net](http://stackoverflow.com/questions/18720549/share-dll-between-2-process-in-net), [Can a Singleton Class inside a DLL be shared across processes?](http://stackoverflow.com/questions/1038111/can-a-singleton-class-inside-a-dll-be-shared-across-processes). Please try to search first. – CodeCaster Oct 03 '14 at 09:03
  • Thank you CodeCaster. I am aware of several IPC options, but If I use them I need to implement a protocol bymyself, for each method that I call, for example. I am looking for a way that I will not have to implement a specific protocol for my methods on the shared class, but simply to call them as I call them now.. just to "flag" the DLL as shared between all processes, and not 1 Instance per process.. – Omer Oct 03 '14 at 09:25

1 Answers1

5

You can't just do that. Assemblies are loaded in a own AppDomain, having it's own process on Windows. So instances stand on their own by default.

You can use some shared memory solutions, like Memory-Mapped Files which are supported since .NET 4.0. A reference for older .NET versions can be found here on SO: How to implement shared memory in .NET?.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325