How to ensure all data has been physically written to disk?

后端 未结 7 1208
执念已碎
执念已碎 2020-11-27 05:44

I understand that .NET FileStream\'s Flush method only writes the current buffer to disk, but dependent on Windows\' disk driver and the hard disk firmware this is no guaran

7条回答
  •  悲哀的现实
    2020-11-27 06:21

    I've noticed that the .NET 4 #Flush(true) doesn't actually write to the disk. We were having strange issues with corrupted data and I found this bug report on the MS site:

    The details tab for the bug report has a test program you can run that will show the issue;

    1. Write a bunch of data to disk
    2. fs.Flush(true). This takes no time (much faster than can possibly written to the disk).
    3. Use the win32 API FlushFileBuffers. This takes a long time.

    I'm changing over to the win32 FlushFileBuffers call...

提交回复
热议问题