File System File System
File System File System
DocFX + Singulink = ♥

Search Results for

    Method FlushToDisk

    FlushToDisk(bool)

    Flushes the file's data and metadata to disk, so that they survive a power loss or an operating system crash.

    Declaration
    void FlushToDisk(bool ignoreNotFound = false)
    Parameters
    Type Name Description
    bool ignoreNotFound

    true to ignore file not found errors; otherwise, false to throw FileNotFoundException if the file was not found.

    Remarks

    The file is opened for writing while it is flushed, because Windows only flushes a file through a handle with write access, so a file that cannot be opened for writing (such as a read-only file) cannot be flushed. Other handles to the file may be open as long as they share writing: the flush itself shares reading, writing and deletion. On Unix, where sharing is advisory, only a handle that shares nothing blocks the flush.

    Only data that the operating system has already been given is flushed. Data that is still in the buffer of an open FileStream is not, so flush or dispose the stream first, or call Flush(bool) on it with true instead, which writes its buffer and then flushes the file to disk.

    The name of a file is an entry of its directory and is not part of the file. To make a file that was created, renamed or moved durable under its name, also call FlushToDisk(bool) on its ParentDirectory.

    Unlike Delete(bool), a file that is not found is not ignored by default: nothing was made durable, which is usually a mistake. If ignoreNotFound is true then what Delete(bool) ignores is ignored: a file that does not exist in a parent directory that does. A parent directory that does not exist and a path that points to a directory still throw.

    Exceptions
    Type Condition
    FileNotFoundException

    The file does not exist and ignoreNotFound is false.

    DirectoryNotFoundException

    The file's parent directory does not exist.

    UnauthorizedIOAccessException

    The file cannot be opened for writing, for example because it is read-only.

    IOException

    The path points to a directory, another handle to the file does not share writing, or the flush failed.

    © Singulink. All rights reserved.