Results 1 to 5 of 5

Thread: [1.0/1.1] How to display file transfer progress [C# 2002]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question [1.0/1.1] 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
    Code:
    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
    Code:
    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,

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [1.0/1.1] How to display file transfer progress [C# 2002]

    Hi there,
    I think you may only need to repaint your fFileTransfer form. Try a
    Code:
    fFileTransfer.Refresh();
    in your loop.

    Hope that helps.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Re: [1.0/1.1] How to display file transfer progress [C# 2002]

    Did you try using "Application.DoEvents" ?...This helped me in some issues with halted forms !

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [1.0/1.1] How to display file transfer progress [C# 2002]

    The best way would be to run your code in the DoWork subroutine of a BackgroundWorker component. You'd use the ReportProgress method to communicate with the main thread.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [1.0/1.1] How to display file transfer progress [C# 2002]

    .NET 1.0 has no BackgroundWorker. You should perform the file transfer in a worker thread and then use delegation to access the UI.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width