Sample Buggy Code (under function recursiveDirectoryCalls):

gsFileName = fInfotmp.Name;
gsCompleteFileName = fInfotmp.FullName;
File.Copy(fInfotmp.FullName, sSecondaryLocation @"\" dirInfoTemp.Name @"\" fInfotmp.Name);
bWorkerSync.ReportProgress(Convert.ToInt32(fInfo_tmp.Length));


The problem that arose was trivial. When the file size was greater than 2 GB in bytes, the fInfo_tmp.Length, which is a long, can handle it, but the Background Worker's Report Progress function can't as it expects an int. So its an overflow and hence an exception.

To get around this, I thought of doing the same

1) If the size if more than 2147483647 (maximum value int can hold, i.e ReportProgress) the break it into smaller chunks of 2147483647 and send these to report progress, In this way we are not compromising on the progress reporting and overcome the limitation.

So here goes the code that I used to solve this...

File.Copy(fInfotmp.FullName, sSecondaryLocation @"\" dirInfoTemp.Name @"\" fInfotmp.Name);
while ((fileSize - 2147483647) >= 2147483647)
{
fileSize = fInfo_tmp.Length - 2147483647;
bWorkerSync.ReportProgress(Convert.ToInt32(2147483647));
}
if (fileSize > 2147483647)
{
bWorkerSync.ReportProgress(Convert.ToInt32(2147483647));
bWorkerSync.ReportProgress(Convert.ToInt32(fileSize - 2147483647));
}
else
bWorkerSync.ReportProgress(Convert.ToInt32(fileSize));

Last edited Jun 3, 2009 at 7:57 PM by gouravdas, version 1

Comments

No comments yet.