Changeset 15444 for branches/EnhancedProgress
- Timestamp:
- 11/02/17 16:55:54 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r15417 r15444 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading; 26 27 using System.Threading.Tasks; 27 28 using System.Windows.Forms; … … 41 42 42 43 private readonly Progress progress = new Progress(); 44 private CancellationTokenSource cancellationTokenSource; 43 45 44 46 private enum TreeState { Valid, Invalid } … … 153 155 treeChart.Repainted += treeChart_Repainted; 154 156 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress); 157 progress.StopRequested += progress_StopRequested; 155 158 } 156 159 protected override void DeregisterContentEvents() { … … 160 163 treeChart.Repainted -= treeChart_Repainted; 161 164 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false); 165 progress.StopRequested -= progress_StopRequested; 162 166 } 163 167 … … 178 182 } 179 183 184 private void progress_StopRequested(object sender, EventArgs e) { 185 cancellationTokenSource.Cancel(); 186 } 187 180 188 private async void UpdateView() { 181 189 if (Content == null || Content.Model == null || Content.ProblemData == null) return; … … 185 193 progress.Start("Calculate Impact and Replacement Values ...", 0); 186 194 progress.CanBeStopped = true; 195 cancellationTokenSource = new CancellationTokenSource(); 187 196 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 188 if (progress.ProgressState != ProgressState.StopRequested) 189 await Task.Delay(500); // wait for progressbar to finish animation 197 try { 198 await Task.Delay(500, cancellationTokenSource.Token); // wait for progressbar to finish animation 199 } catch (OperationCanceledException) { } 190 200 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 191 201 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
Note: See TracChangeset
for help on using the changeset viewer.