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
171 171 RebuildDataTableAsync(); 172 172 } 173 173 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) { 177 175 string resultName = (string)dataTableComboBox.SelectedItem; 178 176 string rowName = (string)dataRowComboBox.SelectedItem; 179 177 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 { 183 184 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 } 190 186 } 191 187 192 188 private void AddLineToChart(string resultName, string rowName) { -
HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs
350 350 return true; 351 351 } 352 352 353 private void CalculateValues() {353 private async void CalculateValues() { 354 354 if (!VerifyDataLength(true)) 355 355 return; 356 356 357 357 if (data != null && data.All(x => x != null)) { 358 string curItem = (string)groupCompComboBox.SelectedItem; 359 358 360 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); } 362 364 } 363 365 } 364 366 365 private void CalculateValues Async(string groupName) {367 private void CalculateValues(string groupName) { 366 368 CalculateAllGroupsTest(); 367 369 CalculateNormalityTest(); 368 370 CalculatePairwiseTest(groupName); 369 370 Progress.Hide(this);371 371 } 372 372 373 373 private void CalculatePairwise(string groupName) { … … 375 375 if (!VerifyDataLength(false)) 376 376 return; 377 377 378 Progress.ShowOnControl(pairwiseTestGroupBox, "Calculating...", ProgressMode.Indeterminate);379 Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));380 }381 382 private void CalculatePairwiseAsync(string groupName) {383 378 CalculatePairwiseTest(groupName); 384 385 Progress.HideFromControl(pairwiseTestGroupBox);386 379 } 387 380 388 381 private void CalculateAllGroupsTest() { -
HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs
210 210 private void UploadAsync() { 211 211 var message = "Uploading runs to OKB..."; 212 212 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; 222 228 } 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(); 227 232 } 228 Progress.Hide(this);229 ClearRuns();230 233 } 231 234 232 235 private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { -
HeuristicLab.DataPreprocessing.Views/3.4/DataPreprocessingView.cs
173 173 instance = instanceProvider.ImportData(importDialog.Path, getImportType(importDialog), importDialog.CSVFormat); 174 174 } catch (IOException ex) { 175 175 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 { 176 178 Progress.Hide(Content); 177 return;178 179 } 179 180 try { 180 181 Content.Import(instance); -
HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicClassificationSolutionView.cs
22 22 using System; 23 23 using System.ComponentModel; 24 24 using System.Linq; 25 using System.Threading.Tasks; 25 26 using System.Windows.Forms; 26 27 using HeuristicLab.MainForm; 27 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; … … 52 53 view.Show(); 53 54 } 54 55 55 private void exportButton_Click(object sender, EventArgs e) {56 private async void exportButton_Click(object sender, EventArgs e) { 56 57 var exporter = new SymbolicSolutionExcelExporter(); 57 58 exportFileDialog.Filter = exporter.FileTypeFilter; 58 59 if (exportFileDialog.ShowDialog(this) == DialogResult.OK) { 60 var name = exportFileDialog.FileName; 59 61 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); 66 67 } 67 68 } 68 69 } -
HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.cs
22 22 using System; 23 23 using System.ComponentModel; 24 24 using System.Linq; 25 using System.Threading.Tasks; 25 26 using System.Windows.Forms; 26 27 using HeuristicLab.MainForm; 27 28 using HeuristicLab.Problems.DataAnalysis.Views; … … 51 52 view.Show(); 52 53 } 53 54 54 private void exportButton_Click(object sender, EventArgs e) {55 private async void exportButton_Click(object sender, EventArgs e) { 55 56 var exporter = new SymbolicDiscriminantFunctionClassificationSolutionExcelExporter(); 56 57 exportFileDialog.Filter = exporter.FileTypeFilter; 57 58 if (exportFileDialog.ShowDialog(this) == DialogResult.OK) { 59 var name = exportFileDialog.FileName; 58 60 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); 65 66 } 66 67 } 67 68 } -
HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs
22 22 using System; 23 23 using System.ComponentModel; 24 24 using System.Linq; 25 using System.Threading.Tasks; 25 26 using System.Windows.Forms; 26 27 using HeuristicLab.MainForm; 27 28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Views; … … 54 55 view.Content = (SymbolicRegressionSolution)this.Content.Clone(); 55 56 } 56 57 57 private void exportButton_Click(object sender, EventArgs e) {58 private async void exportButton_Click(object sender, EventArgs e) { 58 59 var exporter = new SymbolicSolutionExcelExporter(); 59 60 exportFileDialog.Filter = exporter.FileTypeFilter; 60 61 if (exportFileDialog.ShowDialog(this) == DialogResult.OK) { 61 62 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); 67 69 } 68 70 } 69 71 } -
HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs
24 24 using System; 25 25 using System.Collections.Generic; 26 26 using System.Linq; 27 using System.Threading.Tasks; 27 28 using HeuristicLab.MainForm; 28 29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Optimizer; 30 31 31 using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem; 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 69 69 ToolStripItem.Enabled = runCollection.Any(run => run.Parameters.Any(p => p.Value is IDataAnalysisProblemData)); 70 70 } 71 71 72 public override void Execute() {72 public override async void Execute() { 73 73 IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView; 74 74 var content = activeView.Content; 75 75 Progress.Show(content, "Removing duplicate datasets.", ProgressMode.Indeterminate); 76 76 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 { 81 80 Progress.Hide(content); 82 } , null);81 } 83 82 } 84 83 } 85 84 }