简体   繁体   中英

File.Copy() sync or asycn?

I am using File.Copy(source, dest, true) to copy a file from local to remote with overwrite option. In my case, the dest is a mapped network drive:

File.Copy(source, dest, true);
UnMapDrive(); // unmap the network drive

The problem I have afterward is that the source file may be locked so that I could not delete the file from local.

I guess that it might be caused by File.Copy() call. Not sure if this one is synced process or not. In other words, is the source file released after the call?

Yes, it is released and the File.Copy method blocks the execution until the copy operation completes.

The file may be available for read but locked for deletion.

Check with Process Monitor which process is locking the source file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM