C# winform压缩文件夹带进度条

注意:用了开源的CL.IO.Zip库

pbYSJD是进度条的控件名
btnImport是按钮控件名,当压缩结束之后,使按钮处于激活状态,否则无法点击按钮。
/// <summary>
        /// 压缩文件夹并复制到制定目录
        /// </summary>
        /// <param name="strPath">待压缩的文件夹路径</param>
        /// <param name="strZipPath">需要复制到的目录路径(该路径需要带压缩文件名)</param>
        private void ImportZip(string strPath,string strZipPath)
        {
            ZipHandler handler = ZipHandler.GetInstance();
            TaskFactory fastory = new TaskFactory();
            Task[] tasks = new Task[]
            {
                fastory.StartNew(() =>
                {
                    handler.PackDirectory(strPath, strZipPath, (num) =>
                {
                    pbYSJD.Value = Convert.ToInt32(num);
                });
                })
            };
            fastory.ContinueWhenAll(tasks, TasksEnded);

        }
        private void TasksEnded(Task[] tasks)
        {
            MessageBox.Show("压缩完成", "提示");
            btnImport.Enabled = true;
        }

 

posted @ 2016-11-25 14:56  Creatisan  阅读(2581)  评论(0编辑  收藏  举报