How to notify listeners that MemoryMappedFile created via CreateNew() has been changed? I do not have MemoryMappedFile physically on disc. I want second process starts reading from MMF when MMF is changed by first process. Similar to FileSystemWatcher.Changed event.
MemoryMappedFile mmf = MemoryMappedFile.CreateNew("testmap", 10000);
// Second process has been started and waiting for data in MMF
// Writing could be performed multiple times
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
BinaryWriter writer = new BinaryWriter(stream);
writer.Write("hello world!");
}
Second process code:
// The code below should executes when writing to "testmap" file was finished.
using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("testmap"))
{
using (MemoryMappedViewStream stream = mmf.CreateViewStream())
{
BinaryReader reader = new BinaryReader(stream);
Console.WriteLine("Process A says: {0}", reader.ReadString());
}
}
Updated. Solution is to use Named Pipes MSDN as it was suggested by Piotr.