Changeset 15367


Ignore:
Timestamp:
09/18/17 12:18:47 (2 years ago)
Author:
jkarder
Message:

#2830:

  • the asynchronous calls are now awaited
  • added extension method to flatten and handle inner exceptions of AggregateExceptions
  • fixed some catch clauses
Location:
trunk/sources
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs

    r15287 r15367  
    312312      } catch (OperationCanceledException) {
    313313      } catch (AggregateException ae) {
    314         OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
     314        ae.FlattenAndHandle(new[] { typeof(OperationCanceledException) }, e => OnExceptionOccurred(e));
    315315      } catch (Exception e) {
    316316        OnExceptionOccurred(e);
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/CrossValidationView.cs

    r15287 r15367  
    222222    }
    223223
    224     private void startButton_Click(object sender, EventArgs e) {
    225       Content.StartAsync();
     224    private async void startButton_Click(object sender, EventArgs e) {
     225      await Content.StartAsync();
    226226    }
    227227    private void pauseButton_Click(object sender, EventArgs e) {
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r15287 r15367  
    352352      allAlgorithmsFinished = new ManualResetEventSlim(false);
    353353
     354      var startedTasks = new List<Task>(clonedAlgorithms.Count);
     355
    354356      //start prepared or paused cloned algorithms
    355357      foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) {
     
    360362          lock (locker) {
    361363            if (pausePending || stopPending || ExecutionState != ExecutionState.Started) break;
    362             clonedAlgorithm.StartAsync(cancellationToken);
     364            var task = clonedAlgorithm.StartAsync(cancellationToken);
     365            startedTasks.Add(task);
    363366          }
    364367        }
     
    366369
    367370      allAlgorithmsFinished.Wait();
     371
     372      Task.WaitAll(startedTasks.ToArray()); // to get exceptions not handled within the tasks
    368373    }
    369374
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/Tasks/EngineTask.cs

    r15287 r15367  
    7979    public override void Prepare() { }
    8080
    81     public override void Start() {
     81    public override async void Start() {
    8282      Item.Prepare(initialOperation);
    83       Item.StartAsync();
     83      await Item.StartAsync();
    8484    }
    8585
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/Tasks/OptimizerTask.cs

    r15287 r15367  
    9696    }
    9797
    98     public override void Start() {
     98    public override async void Start() {
    9999      if ((Item is Experiment && OptimizerAsExperiment.Optimizers.Count == 0) || // experiment would not fire OnStopped if it has 0 optimizers
    100100          (Item is BatchRun && OptimizerAsBatchRun.Optimizer == null)) { // batchrun would not fire OnStopped if algorithm == null
    101101        OnTaskStopped();
    102102      } else {
    103         Item.StartAsync();
     103        await Item.StartAsync();
    104104      }
    105105    }
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBAlgorithmView.cs

    r15287 r15367  
    324324      if (Content != null) Content.StoreAlgorithmInEachRun = storeAlgorithmInEachRunCheckBox.Checked;
    325325    }
    326     private void startButton_Click(object sender, EventArgs e) {
    327       Content.StartAsync();
     326    private async void startButton_Click(object sender, EventArgs e) {
     327      await Content.StartAsync();
    328328    }
    329329    private void pauseButton_Click(object sender, EventArgs e) {
  • trunk/sources/HeuristicLab.Common/3.3/AsyncHelper.cs

    r15287 r15367  
    2121
    2222using System;
    23 using System.Linq;
    2423using System.Runtime.ExceptionServices;
    2524using System.Threading;
     
    3837      } catch (OperationCanceledException) {
    3938      } catch (AggregateException ae) {
    40         var e = ae.InnerExceptions.SingleOrDefault() ?? ae;
    41         ExceptionDispatchInfo.Capture(e).Throw();
     39        ae.FlattenAndHandle(new[] { typeof(OperationCanceledException) }, e => ExceptionDispatchInfo.Capture(e).Throw());
    4240      }
    4341    }
  • trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r15287 r15367  
    132132    <Compile Include="Constants.cs" />
    133133    <Compile Include="ArrayExtensions.cs" />
     134    <Compile Include="ExceptionExtensions.cs" />
    134135    <Compile Include="Statistics\EmpiricalCumulativeDistributionFunction.cs" />
    135136    <Compile Include="ListExtensions.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r15287 r15367  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using System.Threading;
    2625using HeuristicLab.Common;
     
    9190      } catch (OperationCanceledException) {
    9291      } catch (AggregateException ae) {
    93         OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
     92        ae.FlattenAndHandle(new[] { typeof(OperationCanceledException) }, e => OnExceptionOccurred(e));
    9493      } catch (Exception e) {
    9594        OnExceptionOccurred(e);
  • trunk/sources/HeuristicLab.DebugEngine/3.3/DebugEngine.cs

    r15287 r15367  
    181181      } catch (OperationCanceledException) {
    182182      } catch (AggregateException ae) {
    183         OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
     183        ae.FlattenAndHandle(new[] { typeof(OperationCanceledException) }, e => OnExceptionOccurred(e));
    184184      } catch (Exception e) {
    185185        OnExceptionOccurred(e);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/IOptimizerView.cs

    r15287 r15367  
    136136
    137137    #region Control events
    138     protected virtual void startButton_Click(object sender, EventArgs e) {
    139       Content.StartAsync();
     138    protected virtual async void startButton_Click(object sender, EventArgs e) {
     139      await Content.StartAsync();
    140140    }
    141141    protected virtual void pauseButton_Click(object sender, EventArgs e) {
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs

    r15302 r15367  
    8484      }
    8585      catch (AggregateException ae) {
    86         OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
     86        ae.FlattenAndHandle(new[] { typeof(OperationCanceledException) }, e => OnExceptionOccurred(e));
    8787      }
    8888      catch (Exception e) {
Note: See TracChangeset for help on using the changeset viewer.