File.Copy problem large number files over network

  • Thread starter Thread starter Radenko_Zec
  • Start date Start date
R

Radenko_Zec

I am using standard File.Copy(source,dest,true) method in C# and I have
problem with copying large number of files.
Here is my code:
foreach (FileInfo file in files)
{
File.Copy(file.FullName,destPath+ "\\" + file.Name, true);
}

This code copies only 5 or 10 files but in "files" collection there is 60
files.
I copy files over local network.
I think that this code (File.Copy) calls
Win32Native.CopyFile(fullPathInternal, dst, !overwrite))
and after that it runs again if foreach but coping is not finished.
After large number requests is send File.Copy is not finished for all files.
Is there a way to get response after File.Copy operation is finished?


Thanks
Radenko
 
Instead of using File.Copy you could just use something like FileStream. In
that case you would have greater control over the copy process and you could
do it either in synchronous or asynchronous manner. There is a lot of
examples out there how to use FileStream. Hope that helps.
 
Back
Top