[ACCEPTED]-What's the difference between FileStream.Flush() and FileStream.Flush(True)?-filestream
It causes the file data that's buffered 9 in the file system cache to be written to 8 disk. That data is normally lazily written, based 7 on the position of the disk write head. Having 6 a gigabyte of cached data is technically 5 possible so it can take quite a while. If 4 this is important to you then consider the 3
FileOptions.WriteThrough option instead. It disables write caching 2 completely. This can be very expensive; you'll 1 discover how slow hard disks really are.
When you call
FileStream "copies to the file 16 any data previously written to the buffer 15 and clears the buffer (except for its encoder 14 state)". Buffer here means internal buffer 13 of
FileStream class. And copying to file is not writing 12 data to disc. It's just passing data to 11 OS.
But, IO operations in Windows OS are 10 also buffered - writing data to disk could 9 be postponed until system will be ready 8 to do it. So, clearing all intermediate 7 buffers enforces writing buffered data to 6 disc. Buffers here means Windows internal 5 buffers [File system cache].
BTW when you 4 close file, all buffered data will be written 3 to disc automatically. So, you need this 2 stuff only if you need data to be flushed 1 before file handle will be closed.
This will make an extra call to flush the 1 buffer to file:
More Related questions