private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { var InputRawPathes = this.fileOpenControl1.FilePathes; ShowInfo("Start execution"); this.ObsFileSelectOption = GetOrInitObsFileSelectOption(); SelectedCount = 0; this.ObsFileSelector = new ObsFileSelector(ObsFileSelectOption, OutputDirectory); this.Invoke(new Action(() => { this.progressBar1.Maximum = InputRawPathes.Length; this.progressBar1.Minimum = 0; this.progressBar1.Step = 1; })); if (IsParallel) { var count = namedIntControl_processCount.GetValue(); ParallelOptions parallelOptions = new ParallelOptions() { MaxDegreeOfParallelism = count }; Parallel.ForEach(InputRawPathes, parallelOptions, (inputPath, state) => { if (IsCancel || this.backgroundWorker1.CancellationPending) { ShowInfo("Canceled at :" + inputPath); state.Stop(); } string subDir = Gdp.Utils.PathUtil.GetSubDirectory(InputRawPathes, inputPath); Process(subDir, ObsFileSelectOption, inputPath); }); } else { foreach (var inputPath in InputRawPathes) { if (IsCancel) { ShowInfo("Canceled at :" + inputPath); break; } string subDir = Gdp.Utils.PathUtil.GetSubDirectory(InputRawPathes, inputPath); Process(subDir, ObsFileSelectOption, inputPath); } } }
protected override void Init() { base.Init(); SelectedCount = 0; ShowInfo("开始执行"); this.ObsFileSelectOption = GetOrInitObsFileSelectOption(); ObsFileSelector = new ObsFileSelector(ObsFileSelectOption, OutputDirectory); }