Exemplo n.º 1
0
        private void WriteHandle(string key, IntPtr handler)
        {
            System.IO.MemoryMappedFiles.MemoryMappedFile mmf = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(key, 1024000);

            using (System.IO.MemoryMappedFiles.MemoryMappedViewStream stream = mmf.CreateViewStream())
            {
                using (System.IO.MemoryMappedFiles.MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor())
                {
                    accessor.Write(0, ref handler);
                }
            }
        }
 private void ReaderThread(object stateInfo)
 {
     // Checks if there is something to read.
     this.IntercomStatus = IpcMMFinterComSF.MMFinterComTStatus.TryingToRead;
     this.reading        = accessor.ReadBoolean(ReadPosition + DATA_AVAILABLE_OFFSET);
     if (this.reading)
     {
         this.IntercomStatus = IpcMMFinterComSF.MMFinterComTStatus.ReadingData;
         // Checks how many bytes to read.
         int availableBytes = accessor.ReadInt32(ReadPosition + DATA_LENGTH_OFFSET);
         this.ReadData = new byte[availableBytes];
         // Reads the byte array.
         int read = accessor.ReadArray <byte>(ReadPosition + DATA_OFFSET, this.ReadData, 0, availableBytes);
         // Sets the flag used to signal that there aren't available data anymore.
         accessor.Write(ReadPosition + DATA_AVAILABLE_OFFSET, false);
         // Sets the flag used to signal that data has been read.
         accessor.Write(ReadPosition + READ_CONFIRM_OFFSET, true);
         this.IntercomStatus = IpcMMFinterComSF.MMFinterComTStatus.FinishedReading;
     }
     else
     {
         this.IntercomStatus = IpcMMFinterComSF.MMFinterComTStatus._Null;
     }
 }