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
File Transfer FormCode: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();
Where tb = TextBox (to display the FileName, Source, and Destination to the User).Code:public void SetDisplay(string sFile, string sSourcePath, string sDestinationPath) { tbFileName.Text = sFileName; tbSource.Text = sSourcePath; tbDestination.Text = sDestinationPath; }
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,




Reply With Quote