What's the difference between FileStream.Flush() and FileStream.Flush(True)?

cooldfish picture cooldfish · Feb 7, 2011 · Viewed 10.6k times · Source

MSDN says that FileStream.Flush(True) "also clears all intermediate file buffers.".

What does "all intermediate file buffers" mean exactly?

Answer

Hans Passant picture Hans Passant · Feb 7, 2011

It causes the file data that's buffered in the file system cache to be written to disk. That data is normally lazily written, based on the position of the disk write head. Having a gigabyte of cached data is technically possible so it can take quite a while. If this is important to you then consider the FileOptions.WriteThrough option instead. It disables write caching completely. This can be very expensive; you'll discover how slow hard disks really are.