How to display file transfer progress [C# 2002]

This is going to be an age-old question - I have a form that will perform IO File Transfer of certain files (10-20 of them) and this can take up to 10 minutes, during the file transfer period I want to display to the user a form that indicates what file is currently being copied.

So - to that end - I created a new form (frmFileTransfer) that will display the File Name, Source, and Destination to the user while the IO File Copy is occuring - so I did something like this:

Main Form

this.hide();
frmFileTransfer fFileTransfer = new frmFileTransfer;
fFileTransfer.show();
foreach (string sFile in sFilesToCopy)
{
string sSource = ...;
string sDestination = ...;
fFileTransfer.SetDisplay(sFile, sSource, sDestination);
File.Copy(sSource + sFile, sDestination + sFile, true);
}
fFileTransfer.close();
this.show();

File Transfer Form

public void SetDisplay(string sFile, string sSourcePath, string sDestinationPath)
{
tbFileName.Text = sFileName;
tbSource.Text = sSourcePath;
tbDestination.Text = sDestinationPath;
}

Where tb = TextBox (to display the FileName, Source, and Destination to the User).

Most of you are already reading this going "doh this won't work" as I assume I am violating some thread laws but obviously this method ends up blocking (holding hostage) both forms (the calling one doing the file transfer as well as fFileTransfer) - what can I do to unblock fFileTransfer so that it can show the progress to the user without freezing up as it does now?

I thought forms where seperate threads so I don't see why fFileTransfer is blocked at all when the IO File Copy occurs...I thought of using a delegate I just have no clue how that could be implemented...

Any help would be greatly appreciated.
Thanks,
[1887 byte] By [Shaitan00] at [2007-11-20 9:36:35]
# 1 Re: How to display file transfer progress [C# 2002]
A smarter way (in my opinion) is to create a Copy File Form with a specialized constructor.

In this constructor, you provide all files to be copied with their destination so the form itself will handle the copying.

Then, you have the file copying process embedded in the form (this will only work if you always want to show the form). Then you can simply use copyForm.ShowDialog() and wait for it to return.

Inside the Copy File form, you have to use a separate thread that handles the real file copy. Then, you have to invoke a function that will handle the file progress update, like describe in this topic (http://www.dev-archive.com/forum/showpost.php?p=1603703&postcount=2).

Best regards,
Tischnoetentoet at 2007-11-9 11:34:24 >