0

I am opening an executable from a C# program, which add some information to a Memory Mapped File. How could I signal the parent process that the information was added into the MMF and it can read it? The child process will be killed as soon as the parent read from the MMF.

I did try to set the Exited event on the process, but this is not a good solution, because I don't want my child process to close until the parent didn't read the information from the file. I set the parent process to WaitForExit() (to wait for the child process to finish), so it doesn't start reading from the MMF while the child didn't finish, but also I don't want a finish signal of the child process, I just want a signal that it added the info to the MMF.

How could I solve this?

nb-1999
  • 29
  • 3
  • 1
    Does this answer your question? [What is the simplest method of inter-process communication between 2 C# processes?](https://stackoverflow.com/questions/528652/what-is-the-simplest-method-of-inter-process-communication-between-2-c-sharp-pro) – Tomsen Jan 18 '23 at 14:41
  • 1
    Are you sure you want to use a memory mapped file for that and not a pipe? – GSerg Jan 18 '23 at 14:41
  • You could use [a named `EventWaitHandle`](https://learn.microsoft.com/en-us/dotnet/api/system.threading.eventwaithandle.-ctor?view=net-7.0#system-threading-eventwaithandle-ctor(system-boolean-system-threading-eventresetmode-system-string)) to do this. Just signal it in the child when it's finished writing data and wait on it (with suitable timeout) in the parent. – Matthew Watson Jan 18 '23 at 14:42
  • @MatthewWatson but how could I do this if the 2 processes are independent? I mean, the first process opens an executable (which code I wrote), how could it access the EventWaitHandle from the child? – nb-1999 Jan 18 '23 at 15:09
  • 1
    Ok, I figured it out. It had to be initialized in the same way as a Mutex, and it actually does what I wanted it to do! Thank you! @MatthewWatson – nb-1999 Jan 18 '23 at 15:29
  • Do you have good reasons to use MMF compared to other IPC methods? How much data do you need to transfer in what time? Have you tested other, simpler, IPC-methods and concluded that they are insufficient? – JonasH Jan 18 '23 at 16:11

0 Answers0