Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15444


Ignore:
Timestamp:
11/02/17 16:55:54 (7 years ago)
Author:
pfleck
Message:

#2845 Cancel the artificial delay if progress is stopped.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r15417 r15444  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading;
    2627using System.Threading.Tasks;
    2728using System.Windows.Forms;
     
    4142
    4243    private readonly Progress progress = new Progress();
     44    private CancellationTokenSource cancellationTokenSource;
    4345
    4446    private enum TreeState { Valid, Invalid }
     
    153155      treeChart.Repainted += treeChart_Repainted;
    154156      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress);
     157      progress.StopRequested += progress_StopRequested;
    155158    }
    156159    protected override void DeregisterContentEvents() {
     
    160163      treeChart.Repainted -= treeChart_Repainted;
    161164      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false);
     165      progress.StopRequested -= progress_StopRequested;
    162166    }
    163167
     
    178182    }
    179183
     184    private void progress_StopRequested(object sender, EventArgs e) {
     185      cancellationTokenSource.Cancel();
     186    }
     187
    180188    private async void UpdateView() {
    181189      if (Content == null || Content.Model == null || Content.ProblemData == null) return;
     
    185193      progress.Start("Calculate Impact and Replacement Values ...", 0);
    186194      progress.CanBeStopped = true;
     195      cancellationTokenSource = new CancellationTokenSource();
    187196      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) { }
    190200      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    191201      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
Note: See TracChangeset for help on using the changeset viewer.