Is it possible to split the same dll data into two different processes?

I have two different C # applications that work simultaneously.

I would like both of them to have access to the same "instance" of the DLL (also in C #).

The DLL stores some data that I would like to return, depending on which of the two applications requests it.

My DLL is thread safe, so I was hoping it would be possible, but I'm not sure how to do this.

Any help or advice would be greatly appreciated.

+6
c # process dll shared
source share
5 answers

The process space will be different, therefore, for example, global variables in a DLL will be specific to each individual process. It is possible that the code in memory will be shared (Windows usually uses reference counting to make this part more efficient).

If you want to exchange information available in a DLL between two processes, then it seems likely that you will need to use some kind of IPC (interprocess communication) mechanism, such as sockets, shared memory, channels, etc.

+5
source share

There is no instance in the DLL; it is loaded into the host process. Link to the assembly in both applications and the use of its classes / methods.

If you want to avoid deploying the same assembly for both applications, you can put it in the GAC .

0
source share

It is possible. You can install the DLL in the GAC (a strong name assembly is required) so that both applications have easy access to it.

Or paste it into a folder and ask both applications to find this folder for the dll.

MSDN Support Article

<configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="MyAssembly2" culture="neutral" publicKeyToken="307041694a995978"/> <codeBase version="1.0.1524.23149" href="FILE://C:/Myassemblies/MyAssembly2.dll"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> 
0
source share

I don't know if this can be done in C #, but in C ++ you can also use shared memory partitions if the sharing information is not too complicated. You just need to synchronize access to this ressource using, for example, mutex

Good related article: http://www.codeproject.com/KB/threads/SharedMemory_IPC_Threads.aspx

Good luck

0
source share

If your DLL creates a named MemoryMappedFile (in memory or on disk), then two applications can share the memory created by the DLL. Each application will have a different pointer to shared memory, but the memory will be shared. You must use the same name for shared memory, and you yourself, how safe it is for threads between processes. (Named semaphores or mutexes will work, CriticalSection will not.)

0
source share

All Articles