I have a task thread that runs continuous loop and performs read using mapped memory file. When from another application information writes information to the mapped memory file the loop in the other application running the task read only retrieves that information on a using win32 mapped memory file methods are used and not c# native memory mapped file methods.
For example here is the code using win32 mapped memory file methods in a task thread and this works. When the information is written to the mapped memory file from another application the Marchal.Copy in the task thread method retrieves information
IntPtr
_iFileMappingHandle,
_iFileMapStartAddress;
_iFileMappingHandle = Win32.CreateFileMapping(Win32.InvalidFileHandle, 0,
Win32.FileProtection.ReadWrite,
0, (uint)Size, Name);
_iFileMapStartAddress = Win32.MapViewOfFile(_iFileMappingHandle,
Win32.FileRights.ReadWrite, 0, 0, 0);
var autoReset = new EventWaitHandle(true, EventResetMode.AutoReset, LockName);
if (autoReset.WaitOne(5000))
{
byte[] bTemp = new byte[Size];
Marshal.Copy(_iFileMapStartAddress, bTemp, 0, 512);
But if use the c# memory mapped file methods shown below is used in the same task thread the Read method never retrieves the information written to mapped memory file from the other application. Any suggestion on how to Read method to work? If needed leave me and email address I can post a demo code on github for download, or email the source code if you like.
var mmf = MemoryMappedFile.CreateOrOpen(Name
, Size
, MemoryMappedFileAccess.ReadWrite);
var viewSteam = mmf.CreateViewStream(0, Size);
var autoReset = new EventWaitHandle(true, EventResetMode.AutoReset, LockName);
while (!cancellationToken.IsCancellationRequested)
{
if (autoReset.WaitOne(5000))
{
byte[] bTemp = new byte[Size];
viewSteam.Read(bTemp, 0, Size);