下面是我得代码,文件总共大小有40M,1W个文件。我Copy到目标路径差不多要10来分钟,求大神帮解决下,如果加个比较的简单进度条来显示进度要怎么写?
     private void button9_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "")
            {
                MessageBox.Show("Path is empty! ");
                return;
            }
            try
            {
                for (int j = 0; j < this.listBox2.Items.Count; j++)
                {
                    for (int i = 0; i < this.listBox3.Items.Count; i++)
                    {
                        if (bool.Parse((this.listBox2.Items[j].ToString().Equals(this.listBox3.Items[i].ToString())).ToString()))
                        {
                            // this.listBox2.Items.Remove(this.listBox3.Items[j].ToString());
                            string a = this.listBox2.Items[j].ToString();
                            string b = "B_F_SENSUS_" + a.Substring(0, 4) + "_" + a.Substring(4, 2) + "." + a.Substring(6, 2) + "." + a.Substring(8, 2)
                 + "." + a.Substring(10, 2) + "." + a.Substring(12, 2) + "." + a.Substring(14, 2);
                            CopyDirectory(this.label1.Text, this.textBox1.Text, b);
                        }                    }
                }                MessageBox.Show("OK", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            
        }
        private void CopyDirectory(string srcdir, string desdir,string name)
        {            try
            {
                string folderName = srcdir.Substring(srcdir.LastIndexOf("\\") + 1);                string desfolderdir = desdir + "\\" + folderName;                if (desdir.LastIndexOf("\\") == (desdir.Length - 1))
                {
                    desfolderdir = desdir + folderName;
                }
                string[] filenames = Directory.GetFileSystemEntries(srcdir);                foreach (string file in filenames)// 遍历所有的文件和目录
                {
                    if (file.Equals(this.label1.Text + '\\' + name+".dat"))//路径全名称
                    {
                        string srcfileName = file.Substring(file.LastIndexOf("\\") + 1);                        srcfileName = desfolderdir + "\\" + srcfileName;
                        if (!Directory.Exists(desfolderdir))
                        {
                            Directory.CreateDirectory(desfolderdir);
                        }                        File.Copy(file, srcfileName, true);
                    }
                 
                }
            }            catch (Exception ex)
            {                 MessageBox.Show(ex.ToString());
            }
        }

解决方案 »

  1.   

    首先你要获得总共文件数,然后copy一个就更新一些processbar啊
    或者你用api函数 SHFileOperation调用windows自己的copy功能
      

  2.   

    求优化啊。。进度条搞出来了,这copy数据真的是慢啊
      

  3.   

    如果连带着原文件结构一起复制的话,可以考虑多线程COPY,丝毫无冲突
      

  4.   

    查文件用:Everything-1.2.1.371.exe
    拷贝文件用:FastCopy.exe
      

  5.   


    多线程COPY这个有什么参考代码资料吗?
      

  6.   

    这倒没有,我以前写的demo找不到了,思路就是先分组,分组完毕后直接起N个线程,执行各组copy命令。
    每组各自写各自的工作日志,所有组都执行完了,依次检查日志情况,根据日志整理目的文件夹。最后的检查也可以不要。