'ZipFile.ExtractToDirectory locking file(s) briefly on large zip files?

I have a 110MB zip file that I am extracting using ZipFile.ExtractToDirectory. After I extract the zip file, I use Directory.Move to rename the folder. However, when calling Directory.Move I get permission denied exception for access to the folder where the zip file was originally extracted. If I add a short delay, like 500ms, Directory.Move works.

ZipFile.ExtractToDirectory(zip, dest, true); //Extract zip file to destination
Directory.Move(dest, newName); //Rename folder; newName is full path and does not exist

The above code works fine for smaller zip files, like 10MB. The below consistently works for larger file sizes:

ZipFile.ExtractToDirectory(zip, dest, true); //Extract zip file to destination
Thread.Sleep(500)
Directory.Move(dest, newName); //Rename folder; newName is full path and does not exist

Why do larger files requiring a short delay between extracting and moving? Is there a more robust way to do this other than just add a delay?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source