BackgroundWorker and ProgressBar

I want to display the status in a ProgressBar when copying large files across the network. I am using FileInfo.CopyTo method within the DoWork Method of the BackgroundWorker class (please see the code below). How am I able to fire events while the copying is taking place to update the ProgressBar. The problem is that the execution enters FileInfo.CopyTo method and does not leave until the process is complete.

Hope this makes sense.



privatevoid backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {

BackgroundWorker worker = senderas BackgroundWorker;
reached = 0;
fileInfoFrom =new FileInfo(@"C:\Temp\Path1\Test.zip");
fileInfoTo =new FileInfo(@"C:\Temp\Path2\Test.zip");


fs = (fileInfoTo.Exists) ? fileInfoTo.Length : 0f;
fileInfoFrom.CopyTo(@"C:\Temp\Path2\Test.zip",true);
/* thought aboutusing the file size to
* calculate the percentagefor the progressbar*/
int completed =
(int)((float)fs / (float)fileInfoFrom.Length * 100);
if (completed > reached) {
reached = completed;
worker.ReportProgress(completed);
}
}

[1732 byte] By [SunsOfFun] at [2007-12-17]
# 1
Depending on whether you are using .net 1 or 2, it's very easy or just quite easy!

Full instructions here:
http://msdn.microsoft.com/msdnmag/issues/05/02/NETMatters/

simonl1980 at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...