Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do fsync() in C#?

Tags:

c#

.net

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#?

like image 393
cooldfish Avatar asked Dec 19 '25 17:12

cooldfish


1 Answers

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.

like image 115
Simone Avatar answered Dec 21 '25 05:12

Simone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!