Results 1 to 3 of 3

Thread: [2005] How to tell when a file copy has finished

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    [2005] How to tell when a file copy has finished

    Hi All,

    I have a form that starts a background worker when it loads and basically acts as a progress form to show how far the file copy has got (it copies various files to various locations so I dont want to use the standard windows copy dialog box cos I'll have loads appearing). If the user clicks cancel or closes the form I want the operation to cancel, which I have done by testing whether or not the worker is cancellationpending before each file copy starts. So if it is cancel pending then I just exit the sub and close the form. In some cases though if there are a lot of files to copy then this means files will still be being copied in the background without the user knowing because the form has closed. So basically I want a way of being able to keep the form open (displaying "cancelling..." or something similar) temporarily until the copy has finished. Or a way to cancel the file copy immediatley would be even better. I have tried using the worker.isbusy property but this doesnt work, it just says the worker isnt busy as soon as the form closes even if there are still files being copied.

    Thanks
    Chris

  2. #2

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] How to tell when a file copy has finished

    anyone?

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

    Re: [2005] How to tell when a file copy has finished

    Don't close the form until the task has finished. In the Click event handler of the Cancel button just disable the button so it can't be pressed again and then cancel the BackgroundWorker. You then close the form in the BackgroundWorker's RunWorkerCompleted event handler, so it happens when the operation completes, cancelled or not.
    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