Why isn't there an asynchronous file delete in .net?

Error processing SSI file


  1. Barrett

    • 2015/2/6

    How about this:

    public static class FileExtensions {
       public static Task DeleteAsync(this FileInfo fi) {
          return Task.Factory.StartNew(() => fi.Delete() );

    Then you can just do:

    FileInfo fi = new FileInfo(fileName);
    await fi.DeleteAsync(); // C# 5
    fi.DeleteAsync().Wait(); // C# 4
  2. Ibrahim

    • 2019/10/3

    The ampersand is an ancient symbol from the Latin “et” meaning “and”. When the two letters e and t were run together in writing they gradually took on the shape 

  3. Prince

    • 2016/12/25

    This is the newest place to search, delivering top results from across the web. Content updated daily for isn net.

  4. Griffin

    • 2019/4/9

    In HTML (the language of the web), & and < among other symbols are used as part of the language, so when someone uses & to mean and , HTML has to translate it ( 

  5. Ferrari

    • 2019/6/19

    If nothing else has the file open, opening a FileStream with FileOptions.DeleteOnClose will cause Windows delete the file when the stream is closed. This may help you if you're already opening a FileStream to do async reading/writing, though if you need to wait for the deletion to finish it doesn't help you (although according to @JoelFan waiting for File.Delete to finish doesn't guarantee the file is actually deleted anyway).

    Interestingly enough, in testing against a network share, it seems that opening the stream as such and doing nothing with it is significantly faster (~40%) than File.Delete:

    using (new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.DeleteOnClose)) { }
  6. Eden

    • 2015/12/31

    Why isn't Trump in jail? Former George W. Bush lawyer says Biden's DOJ is protecting him Onetime White House lawyer Richard Painter: Federal prosecutors love presidential power more than actual

  7. Callahan

    • 2017/2/16

    & is HTML for "Start of a character reference". & is the character reference for "An ampersand". ¤t; is not a standard character 

  8. Lian

    • 2020/7/13

    Why waiting until next year isn't a good strategy for frustrated homebuyers Though it has lost some of its thunder, the COVID-19 real estate boom continues to reverberate across the U.S.

  9. Grassi

    • 2017/11/21

    This would be useful. DeleteFile could take up to 30s if deleting on a disconnected network share.

    The reason is likely to be that there is no native function to delete a file asynchronously. The managed APIs generally are wrappers around the unmanaged ones.

    Now why is there no native asynchronous file delete API? Native async deletion is hard to implement on Windows as it is. DeleteFile does in pseudocode CreateFile plus NtSetInformationFile(Disposition, Delete) plus CloseHandle. There is no async CreateFile (in my opinion a design bug in Windows). NtSetInformationFile just sets a flag on the file data structure in the kernel. It can't be asynchronous. The actual deletion happens when the last handle is closed. I think this might make CloseHandle blocking which is another design issue in Windows. There is no async CloseHandle.

  10. Hassan

    • 2017/3/16

    Reader's question: When do you use an ampersand (&) instead of 'and'? · Answer: You can use ampersands in titles, signage and website buttons where space is 

  11. Legacy

    • 2019/8/15

    On the ultraprocessed diet, the subjects on average consumed 500 more calories a day and gained two pounds. A possible reason: The participants’ levels of PYY, a hormone that suppresses appetite

  12. Lucca

    • 2021/8/23

    The ampersand is also known more commonly as the “and sign. when you use an & instead of the word “and,” in other words.

  13. Fisher

    • 2016/4/12

    I may be wrong, but in the case someone tries to access the same file on a cross thread operation, it would be needed to block the file for access until the delete operation is completed.

  14. Ahmad

    • 2020/10/28

    A large swath of workers left the American job market after the pandemic hit, and they don’t seem to be in any hurry to come back. The labor participation rate—people who have jobs or are

  15. Morgan

    • 2020/7/8

    That's why we assembled this easy list of ampersand usage rules. The tendency to overuse & has worsened as less formal digital communication ( 

  16. Benedetti

    • 2015/12/2

    Here’s Why It Probably Isn’t Going Anywhere. Share on Facebook Share on Twitter. Politics Sports Science Podcasts Video ABC News Oct. 7, 2021, at

  17. Murati

    • 2017/5/31

    The File class doesn't expose an asynchronous file deletion method; however, through the use of the FileStream class, an asynchronous file deletion can still be performed by taking advantage of a specific one of the 13 constructor overloads provided. The following code will delete a file asynchronously:

    using (new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.None, 1, FileOptions.DeleteOnClose | FileOptions.Asynchronous)) ;

    I haven't tested it very much, so you may have to modify the usage slightly. (You may want to change FileShare.None to something else if file access by other threads should not be blocked during deletion.) Also, since this code doesn't return any derivation of Task, it would probably be valid to run it with the Task.Run method. Basically, it performs a file deletion which is actually asynchronous on the I/O level, so offloading it onto a thread pool should be okay in this case.

  18. Harrison

    • 2019/7/18

    There are very, very few acceptable uses of & in proper written English. Here are some of them: & is especially common when joining names to indicate a firm 

  19. Cason

    • 2015/7/5

    Why NBC’s ‘Law & Order’ Revival Isn’t a Peacock Original. As WarnerMedia and Disney make some of their biggest originals exclusive to their respective streaming services, NBCUniversal

  20. Lucca

    • 2020/6/27

    Example: * a where * is pointer to the variable a. to the variable a. & operator is used to get the address of the variable. Why do we use macro?

  21. Lewis

    • 2016/5/22

    Orange Football; Why the Iowa game isn’t a must-win for Penn State’s playoff hopes: The College Football Playoff Show

  22. Gordon

    • 2021/5/5

    And Per Se &. Technically, the word ampersand is a mondegreen–meaning a jumble of words that is routinely misheard–created from the phrase “and 

  23. Kevin

    • 2018/5/16

    This is the newest place to search, delivering top results from across the web. Content updated daily for isn net.

  24. Arthur

    • 2017/11/17

    This is the newest place to search, delivering top results from across the web. Find content updated daily for isn program.

Comments are closed.

More Posts