title: Can't flush Memory-Mapped File to disk without stopping host process
body: <p>I have a memory-mapped file and need to periodically flush the contents of it to disk so external products can copy it and read it. At the moment, the file is never updated until I close the hosting process. </p>
  
  <p>Here is the setup of the mapped file:</p>
  
  <blockquote>
    <p>MemoryMappedFile _memoryMappedFile =
    MemoryMappedFile.CreateFromFile(fileName, FileMode.OpenOrCreate,
    cacheName, maxBytes, MemoryMappedFileAccess.ReadWrite);</p>
    
    <p>MemoryMappedViewStream _viewAccessor =
    _memoryMappedFile.CreateViewStream();</p>
  </blockquote>
  
  <p>Here is how I write to it:</p>
  
  <blockquote>
    <p>byte[] message = Encoding.UTF8.GetBytes(content);</p>
    
    <p>_viewAccessor.Write(message, 0, message.Length);
    _viewAccessor.Flush();</p>
  </blockquote>
  
  <p>Ideally, I plan to call the <code>flush</code> method about once a minute, but at the moment it does not seem to have any effect. How can I get this to flush?</p>
  
  <p><em>Note: I've also tried using the <code>MemoryMappedViewAccessor</code> type, but is didn't work either.</em></p>