I use a simple code:
File.Copy(source, destination, true);
To copy a file from a UNC path (source) to a local path (destination). The third parameter makes it that if the file is already there, it will be overwritten.
This works 99%. However, when the source file is locked, I sometimes saw this error:
The process cannot access the file '\xxxx\aaaa.dll' because it is being used by another process.
Then the destination file still disappeared. I can only think that File.Copy
first deleted the local file and then when it is trying to copy things over, it failed and throw exception?
It that so, and how can I prevent this?