What would be the best way to change the timeout depending on the file size when trying to delete it
I want to make sure the file I'm moving doesn't exist at it's destination. This is what I'm doing
// delete if exists already
if (File.Exists(target))
{
File.Delete(target);
}
// move to target
File.Move(source, target);
But sometime, the file is not completely deleted when the program 开发者_开发知识库hit File.Move. To fix this I'm planning on using a FileSystemWatcher to resume the flow after the file have been successfully deleted. But I don't want to wait for ever so i want to put a timeout on the FileSystemWatcher so that after a while it resume the flow even if the file is not deleted.
I would like to make that timeout a function of the size of the file. So let's say if the file is 1MB, the timeout would be 1 second but if it was 10MB it would be 10 second. Does anybody now the best way to choose this timeout or should I just use a fixed timeout what ever the size of the file.
Do it the other way around:
// passing true as the 3rd param to Copy() causes it to overwrite the target file
File.Copy(source, target, true);
File.Delete(source);
(If there were a File.Move(string, string, bool)
, I'd say use that, but there isn't.)
精彩评论