//合并PDF private void btnMerge_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.SelectedPath = @"D:\temp\中国教师报"; dialog.Description = "请选择文件保存路径"; if (dialog.ShowDialog() == DialogResult.OK) { //选择处理文件夹 string foldPath = dialog.SelectedPath; //选择保存文件夹 FolderBrowserDialog saveDialog = new FolderBrowserDialog(); saveDialog.SelectedPath = foldPath; if (saveDialog.ShowDialog() == DialogResult.OK) { string savePath = saveDialog.SelectedPath; MergePdfDto dto = new MergePdfDto() { DestPath = savePath, SourcePath = foldPath }; Thread thread = new Thread(new ParameterizedThreadStart(MergeDirPdf)); thread.Start(dto); } } }
private void MergeDirPdf(Object dto) { MergePdfDto param = dto as MergePdfDto; string[] dirs = Directory.GetDirectories(param.SourcePath); Parallel.ForEach <string>(dirs, dir => { MergePdf(dir, param.DestPath); string tips = $"{Path.GetFileName(dir)}.pdf合并完成"; labTips.Invoke(new Action <String>(p => { labTips.Text = p; }), tips); }); MessageBox.Show("合并完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }