Executes twice for the loop

Can someone tell me why this is processing all files and then doing it again? It drives me crazy. Thanks to

    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;
    }

      

+1


a source to share


2 answers


Check if you bind the event handler twice HP3BackgroundWorker_DoWork

?



+8


a source


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



+2


a source







All Articles