When I have a non empty directory, createdirectory does not create directory after delete.
public void SetupRootPath(string path)
{
Directory.CreateDirectory(path);
Directory.Delete(path, true);
Directory.CreateDirectory(path);
}
wondering if Directory.Delete is really a synchronous call?
.Net Version : .net core 2.2
Platform: windows 10
cc: @JeremyKuhne
@sameerkattel Which Windows 10 build are you using? Delete has never been truly synchronous, it would simply mark the file/directory for deletion. The file/directory would not be removed until all handles are closed. When you make these calls quickly in succession what typically happens is this:
In Windows 10 1903 deletion was changed so that it immediately moves the entry to a hidden location, freeing up the name for use again. While this particular issue you're seeing shouldn't happen anymore, it's still a bad pattern to use as all prior versions of Windows do this and some apps may opt to turn on the old behavior for compatibility.
@JeremyKuhne I see. Thanks for the info! Btw here is my windows specifications:
Version 1903
OS Build 18362.295
Most helpful comment
@sameerkattel Which Windows 10 build are you using? Delete has never been truly synchronous, it would simply mark the file/directory for deletion. The file/directory would not be removed until all handles are closed. When you make these calls quickly in succession what typically happens is this:
In Windows 10 1903 deletion was changed so that it immediately moves the entry to a hidden location, freeing up the name for use again. While this particular issue you're seeing shouldn't happen anymore, it's still a bad pattern to use as all prior versions of Windows do this and some apps may opt to turn on the old behavior for compatibility.