tags:

views:

184

answers:

2

Can someone tell me why this processes all the files and then does it again? Its driving me crazy. Thanks

    private void HP3BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        BackgroundWorker hp3worker = (BackgroundWorker) sender;

        DirectoryInfo hp3Files = new DirectoryInfo(fromPath + @"\hp3\");
        FileInfo[] hp3Filelist = hp3Files.GetFiles("*.*");
        int count = hp3Filelist.Length;

        UseWaitCursor = true;
        for (int i = 0; i < count; i++)
        {
            FileInfo file = hp3Filelist[i];
            try
            {
                File.Copy(fromPath + @"\hp3\" + file.Name, toPath + @"\hp3\" + file.Name, true);
                hp3worker.ReportProgress((int)((float) i / count * 100));
            }
            catch (Exception error)
            {
                MessageBox.Show("Error is " + error);
            }
        }
        UseWaitCursor = false;
    }
+7  A: 

Check if you attached the event handler HP3BackgroundWorker_DoWork twice?

Brian Rasmussen
It was called for twice. I ran through it so many times. I don't know misssed that! Thank you!
JimDel
+2  A: 

Are you sure the function isn't being called twice? That loop looks fine.

Tom Smith