1

有人能告诉我为什么这会处理所有文件然后再做一次吗?这让我疯狂。谢谢

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

2 回答 2

8

检查您是否附加了HP3BackgroundWorker_DoWork两次事件处理程序?

于 2009-05-25T18:28:13.513 回答
2

您确定该函数没有被调用两次吗?那个循环看起来不错。

于 2009-05-25T18:28:14.840 回答