Read Memory-mapped file several times

298 views Asked by At

I'm trying to write an application that opens a memory-mapped file and reads it every time new data is coming from other application.

My question is how my application knows when the new data comes in to read, or it's just continuously looping and read and hope some day it will see new data?

What kind of mechanism Windows provides to deal with repeatedly read of memory-mapped file.

Thanks,

1

There are 1 answers

0
Eric J. On

You can have the program that is updating the memory mapped file raise an event when it writes new data, and have the other program subscribe to that event. It would then read from the memory map when it receives an event notification.

There is a sample project in MSDN that shows how to do this

I have created a library that allows inter-process communication using a shared Memory Mapped File, in which two or more processes can read and write byte arrays. It provides a method to write and an event that is raised every time new data are available. Every operation is performed in background, so your application never blocks while waiting for messages.

https://code.msdn.microsoft.com/windowsdesktop/Inter-process-communication-e96e94e7