Good evening all,
Currently I am working on a program that will automate the backup/restore jobs at the place I work. The rough work has been done, but I am somewhat concerned about the possibility of massive IO operations due to the way my program works.
Here is the scenario:
My colleagues and me sometimes have to do PC transfers. Copying all relevant userdata from one PC, to a networklocation, set up the new PC, copy from network to new PC.=
Our servers/NAS/network are all up to par, so they won't be a problem. But some users still gather quite a bit of data (think along the lines of 5-10GB/15.000-30.000 files).
The program creates a BackgroundWorker for all the relevant folder, then gathers all the files to copy through a List<FileInfo>. Then a foreach loop to go through that list and copy the files as below:
//500KB chosen as buffersize, this allows for very fast (700MB in ~6-7 seconds) transfers without flooding the HD buffer (so far..)
//Should also be safe for network usage.
int bufferSize = (int)(1024 * 1024 * 0.5);
FileStream strIn = new FileStream(CurLoc, FileMode.Open);
FileStream strOut = new FileStream(NewLoc, FileMode.Create);
byte[] buf = new byte[bufferSize];
while (strIn.Position < strIn.Length)
{
int len = strIn.Read(buf, 0, buf.Length);
strOut.Write(buf, 0, len);
//Should update once bufferSize has been tranferred, so should be once every 500KB
SetProBar(strIn.Position, strIn.Length, EPB);
}
//Flush and close streams, otherwise the file will not be properly written
strIn.Flush();
strIn.Close();
strOut.Flush();
strOut.Close();
But I am worried that given the very large amount of files might put IO operations through the roof, and slow the system to a crawl.
So I am kind of looking for a way to limit the copy process to roughly 5 files per BackgroundWorker.
For this I think I should use something like while(filesCopying < 5) or something. But I am not quite sure at what point I should be running this. And how do I make the rest of the foreach wait until it is done copying?
If anybody could shed some light on this, I would be very appreciative!
Good evening all.