Transfer large data between .net applications on same computer

后端 未结 4 1404
野性不改
野性不改 2020-12-29 09:03

I have two .net applications that run on the same machine. The first application is the \'Engine\'. It builds images - image\'s size is about 4M. The second applications is

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 09:47

    Since .NET Framework 4.0 you can use Memory Mapped Files for this, I believe it would be faster than file system based approach since you do not need expensive file system IO operations.

    A memory-mapped file contains the contents of a file in virtual memory. This mapping between a file and memory space enables an application, including multiple processes, to modify the file by reading and writing directly to the memory. Memory-mapped files can be shared across multiple processes. Processes can map to the > same memory-mapped file by using a common name that is assigned by the process that created the file

    So to share MMF across multiple processes you just need to share a MMF name, so you can consider following approach:

    • Engine creates MMF file and share with Viewer just a name (string)
    • View access MMF using MemoryMappedFile.OpenExisting(sharedName) method (see MSDN for an example accessing same MMF from different processes)

    Useful links:

    • Memory-Mapped Files
    • Working with memory mapped files in .NET 4 - highly recommend reading this article which describes why MMF really "is the most efficient way for multiple processes on a single machine to communicate with each other". Basically it show that all other IPC options are MMF-based.

    (From the mentioned above article) If we check other IPC methods we can see the following architecture: enter image description here

提交回复
热议问题