在不停止主机进程的情况下无法将内存映射文件刷新到磁盘
我有一个内存映射文件,需要定期将其内容刷新到磁盘,以便外部产品可以复制并读取它。目前,在我关闭托管进程之前,该文件永远不会更新。
这是映射文件的设置:
内存映射文件_内存映射文件= MemoryMappedFile.CreateFromFile(文件名, FileMode.OpenOrCreate, 缓存名称、最大字节数、MemoryMappedFileAccess.ReadWrite);
MemoryMappedViewStream _viewAccessor = _memoryMappedFile.CreateViewStream();
我是这样写的:
byte[] message = Encoding.UTF8.GetBytes(content);
_viewAccessor.Write(消息, 0, 消息长度); _viewAccessor.Flush();
理想情况下,我计划大约每分钟调用一次 flush
方法,但目前看来没有任何效果。我怎样才能让它冲水?
注意:我也尝试过使用 MemoryMappedViewAccessor
类型,但也不起作用。
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.
Here is the setup of the mapped file:
MemoryMappedFile _memoryMappedFile =
MemoryMappedFile.CreateFromFile(fileName, FileMode.OpenOrCreate,
cacheName, maxBytes, MemoryMappedFileAccess.ReadWrite);MemoryMappedViewStream _viewAccessor =
_memoryMappedFile.CreateViewStream();
Here is how I write to it:
byte[] message = Encoding.UTF8.GetBytes(content);
_viewAccessor.Write(message, 0, message.Length);
_viewAccessor.Flush();
Ideally, I plan to call the flush
method about once a minute, but at the moment it does not seem to have any effect. How can I get this to flush?
Note: I've also tried using the MemoryMappedViewAccessor
type, but is didn't work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论