Skip to content

Instantly share code, notes, and snippets.

@leppie
Created July 3, 2013 12:17
Show Gist options
  • Save leppie/5917429 to your computer and use it in GitHub Desktop.
Save leppie/5917429 to your computer and use it in GitHub Desktop.
.NET 4.5
[SecuritySafeCritical]
public virtual void Flush(bool flushToDisk)
{
if (this._handle.IsClosed)
{
__Error.FileNotOpen();
}
this.FlushInternalBuffer();
if (flushToDisk && this.CanWrite)
{
this.FlushOSBuffer();
}
}
private void FlushInternalBuffer()
{
if (this._writePos > 0)
{
this.FlushWrite(false);
return;
}
if (this._readPos < this._readLen && this.CanSeek)
{
this.FlushRead();
}
}
[SecuritySafeCritical]
private void FlushOSBuffer()
{
if (!Win32Native.FlushFileBuffers(this._handle))
{
__Error.WinIOError();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment