How to do fsync() in C#?
I'm working on a project related to databases in C#. After each transaction commit, I want the db to move all the buffered data onto disk. In Linux, fflush() + fsync() would provide what I want. To get the same开发者_开发知识库 effect, what should I do in C#?
The method corresponding to C' fflush()
is Flush()
of FileStream class.
Anyway, this is related to files, not to databases.
EDIT
If you are targeting 4.0 .NET Framework, there's a new overload that accepts a boolean. According to its description:
Flush(bool flushToDisk)
flushToDisk
Type: System.Boolean
true to flush all intermediate file buffers; otherwise, false.
you should invoke it passing true
.
Generally, when working with something like SQL Server, you don't have control over when the database writes data to disk.
All you should worry about is ensuring the commit
of your transaction is successful.
Which database server are you using?
精彩评论