Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/06/20 16:54:29 (5 years ago)
Author:
pfleck
Message:

#2973

  • Certain events of the TargetControl are now forwarded to the ProgressView in order to correctly dispose and hide the ProgressView.
  • Simplified hiding the ProgressView within the Regression/ClassificationSolutionVariableImpactsView.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionVariableImpactsView.cs

    r17276 r17426  
    2525using System.Threading;
    2626using System.Threading.Tasks;
     27using System.Windows.Forms;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Data;
     
    4041    private CancellationTokenSource cancellationToken = new CancellationTokenSource();
    4142    private List<Tuple<string, double>> rawVariableImpacts = new List<Tuple<string, double>>();
    42     private bool attachedToProgress = false;
    4343
    4444    public new IClassificationSolution Content {
     
    8787      }
    8888    }
    89     protected override void OnHidden(EventArgs e) {
    90       base.OnHidden(e);
     89    protected override void OnVisibleChanged(EventArgs e) {
     90      base.OnVisibleChanged(e);
     91      if (!this.Visible) {
     92        cancellationToken.Cancel();
     93      }
     94    }
     95
     96    protected override void OnClosed(FormClosedEventArgs e) {
     97      base.OnClosed(e);
    9198      cancellationToken.Cancel();
    92 
    93       if (attachedToProgress) {
    94         Progress.Hide(this);
    95         attachedToProgress = false;
    96       }
    9799    }
    98100
     
    133135      variableImpactsArrayView.Caption = Content.Name + " Variable Impacts";
    134136      progress = Progress.Show(this, "Calculating variable impacts for " + Content.Name);
    135       attachedToProgress = true;
    136137      cancellationToken = new CancellationTokenSource();
    137138
     
    145146          .ToList();
    146147
    147         List<Tuple<string, double>> impacts = null;
    148         await Task.Run(() => { impacts = CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress); });
    149         if (impacts == null) { return; }
     148        var impacts = await Task.Run(() => CalculateVariableImpacts(originalVariableOrdering, Content.Model, problemData, Content.EstimatedClassValues, dataPartition, replMethod, factorReplMethod, cancellationToken.Token, progress));
    150149
    151150        rawVariableImpacts.AddRange(impacts);
    152151        UpdateOrdering();
     152      } catch (OperationCanceledException) {
    153153      } finally {
    154         if (attachedToProgress) {
    155           Progress.Hide(this);
    156           attachedToProgress = false;
    157         }
     154        Progress.Hide(this);
    158155      }
    159156    }
     
    180177      var clonedModel = (IClassificationModel)model.Clone();
    181178      foreach (var variableName in originalVariableOrdering) {
    182         if (cancellationToken.Token.IsCancellationRequested) { return null; }
     179        token.ThrowIfCancellationRequested();
    183180        progress.ProgressValue = (double)++i / count;
    184181        progress.Message = string.Format("Calculating impact for variable {0} ({1} of {2})", variableName, i, count);
Note: See TracChangeset for help on using the changeset viewer.