Bizarre directory delete behaviour on SSD drive

前端 未结 6 863
遇见更好的自我
遇见更好的自我 2021-01-01 10:25

Directory c:\\test has 50 or so files in it, no subdirectories.

    If IO.Directory.Exists(\"C:\\test\") Then
        IO.Directory.Delete(\"C:\\test\", True)         


        
6条回答
  •  半阙折子戏
    2021-01-01 11:21

    I suspect that you've found a race condition in NTFS that was previously not exposed since drives didn't exist that were fast enough to hit it. I don't think that TRIM has anything to do with it (though I reserve the right to be wrong!)

    Either way, the proper way to handle this is to put the code in a Retry loop:

    int retries = 3;
    while(true) {
        try {
            doTheOperation();
            break;
        } catch (Exception ex) {
            retries--;
            if (retries == 0) {
                throw;
            }
    
            Thread.Sleep(100);
            continue;
        }        
    }
    

提交回复
热议问题