Free cookie consent management tool by TermsFeed Policy Generator

Ticket #2845: try-finally for Progress.patch

File try-finally for Progress.patch, 13.4 KB (added by pfleck, 5 years ago)
  • HeuristicLab.Analysis.Statistics.Views/3.3/ChartAnalysisView.cs

     
    171171      RebuildDataTableAsync();
    172172    }
    173173
    174     private void addLineToChart_Click(object sender, EventArgs e) {
    175       Progress.Show(this, "Adding fitted lines to charts...", ProgressMode.Indeterminate);
    176 
     174    private async void addLineToChart_Click(object sender, EventArgs e) {
    177175      string resultName = (string)dataTableComboBox.SelectedItem;
    178176      string rowName = (string)dataRowComboBox.SelectedItem;
    179177
    180       var task = Task.Factory.StartNew(() => AddLineToChart(resultName, rowName));
    181 
    182       task.ContinueWith((t) => {
     178      Progress.Show(this, "Adding fitted lines to charts...", ProgressMode.Indeterminate);
     179      try {
     180        await Task.Run(() => AddLineToChart(resultName, rowName));
     181      } catch (Exception exc) {
     182        ErrorHandling.ShowErrorDialog(this, "An error occured while adding lines to charts. ", exc);
     183      } finally {
    183184        Progress.Hide(this);
    184         ErrorHandling.ShowErrorDialog("An error occured while adding lines to charts. ", t.Exception);
    185       }, TaskContinuationOptions.OnlyOnFaulted);
    186 
    187       task.ContinueWith((t) => {
    188         Progress.Hide(this);
    189       }, TaskContinuationOptions.OnlyOnRanToCompletion);
     185      }
    190186    }
    191187
    192188    private void AddLineToChart(string resultName, string rowName) {
  • HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs

     
    350350      return true;
    351351    }
    352352
    353     private void CalculateValues() {
     353    private async void CalculateValues() {
    354354      if (!VerifyDataLength(true))
    355355        return;
    356356
    357357      if (data != null && data.All(x => x != null)) {
     358        string curItem = (string)groupCompComboBox.SelectedItem;
     359
    358360        Progress.Show(this, "Calculating...", ProgressMode.Indeterminate);
    359 
    360         string curItem = (string)groupCompComboBox.SelectedItem;
    361         Task.Factory.StartNew(() => CalculateValuesAsync(curItem));
     361        try {
     362          await Task.Run(() => CalculateValues(curItem));
     363        } finally { Progress.Hide(this); }
    362364      }
    363365    }
    364366
    365     private void CalculateValuesAsync(string groupName) {
     367    private void CalculateValues(string groupName) {
    366368      CalculateAllGroupsTest();
    367369      CalculateNormalityTest();
    368370      CalculatePairwiseTest(groupName);
    369 
    370       Progress.Hide(this);
    371371    }
    372372
    373373    private void CalculatePairwise(string groupName) {
     
    375375      if (!VerifyDataLength(false))
    376376        return;
    377377
    378       Progress.ShowOnControl(pairwiseTestGroupBox, "Calculating...", ProgressMode.Indeterminate);
    379       Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));
    380     }
    381 
    382     private void CalculatePairwiseAsync(string groupName) {
    383378      CalculatePairwiseTest(groupName);
    384 
    385       Progress.HideFromControl(pairwiseTestGroupBox);
    386379    }
    387380
    388381    private void CalculateAllGroupsTest() {
  • HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs

     
    210210    private void UploadAsync() {
    211211      var message = "Uploading runs to OKB...";
    212212      IProgress progress = Progress.Show(this, message);
    213       double count = dataGridView.Rows.Count;
    214       int i = 0;
    215       foreach (DataGridViewRow row in dataGridView.Rows) {
    216         i++;
    217         if (!Convert.ToBoolean(row.Cells[UploadColumn.Name].Value)) continue;
    218         selectedAlgorithm = algorithms.FirstOrDefault(x => x.Name == row.Cells[OKBAlgorithmColumn.Name].Value.ToString());
    219         selectedProblem = problems.FirstOrDefault(x => x.Name == row.Cells[OKBProblemColumn.Name].Value.ToString());
    220         if (selectedAlgorithm == null || selectedProblem == null) {
    221           throw new ArgumentException("Can't retrieve the algorithm/problem to upload");
     213      try {
     214        double count = dataGridView.Rows.Count;
     215        int i = 0;
     216        foreach (DataGridViewRow row in dataGridView.Rows) {
     217          i++;
     218          if (!Convert.ToBoolean(row.Cells[UploadColumn.Name].Value)) continue;
     219          selectedAlgorithm = algorithms.FirstOrDefault(x => x.Name == row.Cells[OKBAlgorithmColumn.Name].Value.ToString());
     220          selectedProblem = problems.FirstOrDefault(x => x.Name == row.Cells[OKBProblemColumn.Name].Value.ToString());
     221          if (selectedAlgorithm == null || selectedProblem == null) {
     222            throw new ArgumentException("Can't retrieve the algorithm/problem to upload");
     223          }
     224
     225          OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id);
     226          run.Store();
     227          progress.ProgressValue = ((double)i) / count;
    222228        }
    223 
    224         OKBRun run = new OKBRun(selectedAlgorithm.Id, selectedProblem.Id, row.Tag as IRun, UserInformation.Instance.User.Id);
    225         run.Store();
    226         progress.ProgressValue = ((double)i) / count;
     229      } finally {
     230        Progress.Hide(this);
     231        ClearRuns();
    227232      }
    228       Progress.Hide(this);
    229       ClearRuns();
    230233    }
    231234
    232235    private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
  • HeuristicLab.DataPreprocessing.Views/3.4/DataPreprocessingView.cs

     
    173173            instance = instanceProvider.ImportData(importDialog.Path, getImportType(importDialog), importDialog.CSVFormat);
    174174          } catch (IOException ex) {
    175175            MessageBox.Show(string.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
     176            return;
     177          } finally {
    176178            Progress.Hide(Content);
    177             return;
    178179          }
    179180          try {
    180181            Content.Import(instance);
  • HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicClassificationSolutionView.cs

     
    2222using System;
    2323using System.ComponentModel;
    2424using System.Linq;
     25using System.Threading.Tasks;
    2526using System.Windows.Forms;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
     
    5253      view.Show();
    5354    }
    5455
    55     private void exportButton_Click(object sender, EventArgs e) {
     56    private async void exportButton_Click(object sender, EventArgs e) {
    5657      var exporter = new SymbolicSolutionExcelExporter();
    5758      exportFileDialog.Filter = exporter.FileTypeFilter;
    5859      if (exportFileDialog.ShowDialog(this) == DialogResult.OK) {
     60        var name = exportFileDialog.FileName;
    5961
    60         var name = exportFileDialog.FileName;
    61         using (BackgroundWorker bg = new BackgroundWorker()) {
    62           Progress.Show(this, "Exportion solution to " + name + ".", ProgressMode.Indeterminate);
    63           bg.DoWork += (o, a) => exporter.Export(Content, name);
    64           bg.RunWorkerCompleted += (o, a) => Progress.Hide(this);
    65           bg.RunWorkerAsync();
     62        Progress.Show(this, "Export solution to " + name + ".", ProgressMode.Indeterminate);
     63        try {
     64          await Task.Run(() => exporter.Export(Content, name));
     65        } finally {
     66          Progress.Hide(this);
    6667        }
    6768      }
    6869    }
  • HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.cs

     
    2222using System;
    2323using System.ComponentModel;
    2424using System.Linq;
     25using System.Threading.Tasks;
    2526using System.Windows.Forms;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.Problems.DataAnalysis.Views;
     
    5152      view.Show();
    5253    }
    5354
    54     private void exportButton_Click(object sender, EventArgs e) {
     55    private async void exportButton_Click(object sender, EventArgs e) {
    5556      var exporter = new SymbolicDiscriminantFunctionClassificationSolutionExcelExporter();
    5657      exportFileDialog.Filter = exporter.FileTypeFilter;
    5758      if (exportFileDialog.ShowDialog(this) == DialogResult.OK) {
     59        var name = exportFileDialog.FileName;
    5860
    59         var name = exportFileDialog.FileName;
    60         using (BackgroundWorker bg = new BackgroundWorker()) {
    61           Progress.Show(this, "Exportion solution to " + name + ".", ProgressMode.Indeterminate);
    62           bg.DoWork += (o, a) => exporter.Export(Content, name);
    63           bg.RunWorkerCompleted += (o, a) => Progress.Hide(this);
    64           bg.RunWorkerAsync();
     61        Progress.Show(this, "Export solution to " + name + ".", ProgressMode.Indeterminate);
     62        try {
     63          await Task.Run(() => exporter.Export(Content, name));
     64        } finally {
     65          Progress.Hide(this);
    6566        }
    6667      }
    6768    }
  • HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs

     
    2222using System;
    2323using System.ComponentModel;
    2424using System.Linq;
     25using System.Threading.Tasks;
    2526using System.Windows.Forms;
    2627using HeuristicLab.MainForm;
    2728using HeuristicLab.Problems.DataAnalysis.Symbolic.Views;
     
    5455      view.Content = (SymbolicRegressionSolution)this.Content.Clone();
    5556    }
    5657
    57     private void exportButton_Click(object sender, EventArgs e) {
     58    private async void exportButton_Click(object sender, EventArgs e) {
    5859      var exporter = new SymbolicSolutionExcelExporter();
    5960      exportFileDialog.Filter = exporter.FileTypeFilter;
    6061      if (exportFileDialog.ShowDialog(this) == DialogResult.OK) {
    6162        var name = exportFileDialog.FileName;
    62         using (BackgroundWorker bg = new BackgroundWorker()) {
    63           Progress.Show(this, "Exporting solution to " + name + ".", ProgressMode.Indeterminate);
    64           bg.DoWork += (o, a) => exporter.Export(Content, name);
    65           bg.RunWorkerCompleted += (o, a) => Progress.Hide(this);
    66           bg.RunWorkerAsync();
     63
     64        Progress.Show(this, "Export solution to " + name + ".", ProgressMode.Indeterminate);
     65        try {
     66          await Task.Run(() => exporter.Export(Content, name));
     67        } finally {
     68          Progress.Hide(this);
    6769        }
    6870      }
    6971    }
  • HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs

     
    2424using System;
    2525using System.Collections.Generic;
    2626using System.Linq;
     27using System.Threading.Tasks;
    2728using HeuristicLab.MainForm;
    2829using HeuristicLab.Optimization;
    2930using HeuristicLab.Optimizer;
    30 
    3131using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem;
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    6969      ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData));
    7070    }
    7171
    72     public override void Execute() {
     72    public override async void Execute() {
    7373      IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
    7474      var content = activeView.Content;
    7575      Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate);
    7676
    77       Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content);
    78 
    79       action.BeginInvoke(activeView, delegate (IAsyncResult result) {
    80         action.EndInvoke(result);
     77      try {
     78        await Task.Run(() => DatasetUtil.RemoveDuplicateDatasets(content));
     79      } finally {
    8180        Progress.Hide(content);
    82       }, null);
     81      }
    8382    }
    8483  }
    8584}