private void btnOK_Click(object sender, EventArgs e) { //需要替换的申报包列表 List <string> importList = new List <string>(); #region 查的需要导入的路径 foreach (TreeNode tn in tvSubDirs.Nodes) { //判断是否被选中 if (tn.Checked) { //读取目录名称中的项目编号 string projectNumber = tn.Text.Substring(0, 11); //将需要处理的申报包添加到列表中 importList.Add(Path.Combine(MainForm.Config.TotalDir, tn.Text)); } } #endregion //检查是否已创建句柄,并调用委托执行UI方法 if (IsHandleCreated) { Invoke(new MethodInvoker(delegate() { //隐藏本窗体 Top = Screen.PrimaryScreen.Bounds.Height * 2; })); } //开始导入 ProgressForm pf = new ProgressForm(); pf.Show(); pf.run(importList.Count, 0, new EventHandler(delegate(object senders, EventArgs ee) { //进度数值 int progressVal = 0; //导入 foreach (string pDir in importList) { try { progressVal++; //读取项目ID string projectNumber = new DirectoryInfo(pDir).Name.Substring(0, 11); //报告进度 pf.reportProgress(progressVal, string.Empty); //报告进度 pf.reportProgress(progressVal, projectNumber + "_开始解压"); //解压ZIP包 unZipDocFiles(projectNumber); //报告进度 pf.reportProgress(progressVal, projectNumber + "_结束解压"); } catch (Exception ex) { MainForm.writeLog(ex.ToString()); } } //检查是否已创建句柄,并调用委托执行UI方法 if (IsHandleCreated) { Invoke(new MethodInvoker(delegate() { try { //关闭进度窗口 pf.Close(); } catch (Exception ex) { MainForm.writeLog(ex.ToString()); } //尝试输出Excel日志 if (errorFileList != null && errorFileList.Count >= 1) { writeErrorExcelFile(); } //关闭窗口 Close(); })); } })); }