Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer large data between .net applications on same computer

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 the 'Viewer'. It shows the images which the 'Engine' sends. The engine sends images every 10-15 seconds.

My question is what is the bast way to pass the images from the engine to the viewer. Currently, I'm using FileSystem for this. The Engine writes the image to file system folder and the viewer getting this file using FileSystemWatcher.

Is that approach ok? Is that reliable?

like image 865
MTs Avatar asked Feb 23 '12 10:02

MTs


People also ask

How can you share your data between two applications?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.

What is used to transfer data from one computer to another?

SSD and HDD drives via SATA cables You can connect your old hard drive to a SATA SSD or eSATA (an external SATA) port in your new computer. After you install the old drive, the operating system in your new PC will read the drive and begin transferring the data over [2].


1 Answers

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

like image 149
sll Avatar answered Sep 29 '22 11:09

sll