Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File.Copy() sync or asycn?

Tags:

c#

.net

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?

like image 503
David.Chu.ca Avatar asked Feb 02 '10 18:02

David.Chu.ca


People also ask

Is await a sync or async?

The await keyword is used in an async function to ensure that all promises returned in the async function are synchronized, ie. they wait for each other. Await eliminates the use of callbacks in . then() and .

Is C# a sync or async?

C# supports both synchronous and asynchronous methods. Let's learn the difference between synchronous and asynchronous and how to code in C#.

What is the difference between Sync and await?

await can only be used in async functions. It is used for calling an async function and waits for it to resolve or reject. await blocks the execution of the code within the async function in which it is located.

What is asynchronous file?

Asynchronous data is data that is not synchronized when it is sent or received. In this type of transmission, signals are sent between the computers and external systems or vice versa in an asynchronous manner.


1 Answers

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.

like image 111
Marek Avatar answered Oct 23 '22 00:10

Marek