Index: /branches/Async/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs
===================================================================
--- /branches/Async/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Algorithms.Benchmarks/3.3/BenchmarkAlgorithm.cs (revision 15232)
@@ -312,6 +312,5 @@
} catch (OperationCanceledException) {
} catch (AggregateException ae) {
- if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]);
- else OnExceptionOccurred(ae);
+ OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
} catch (Exception e) {
OnExceptionOccurred(e);
@@ -324,5 +323,5 @@
public async Task StartAsync() { await StartAsync(CancellationToken.None); }
public async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
Index: /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
===================================================================
--- /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs (revision 15232)
@@ -344,5 +344,5 @@
public async Task StartAsync() { await StartAsync(CancellationToken.None); }
public async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
Index: /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs
===================================================================
--- /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs (revision 15232)
@@ -21,4 +21,5 @@
using System;
+using System.Linq;
using System.Threading;
using HeuristicLab.Common;
@@ -77,6 +78,5 @@
} catch (OperationCanceledException) {
} catch (AggregateException ae) {
- if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]);
- else OnExceptionOccurred(ae);
+ OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
} catch (Exception e) {
OnExceptionOccurred(e);
Index: /branches/Async/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs
===================================================================
--- /branches/Async/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs (revision 15232)
@@ -69,6 +69,5 @@
try {
algorithm.Problem = problem;
- }
- catch (ArgumentException) {
+ } catch (ArgumentException) {
algorithm.Problem = null;
}
@@ -263,5 +262,5 @@
public async Task StartAsync() { await StartAsync(CancellationToken.None); }
public async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
public void Pause() {
Index: /branches/Async/HeuristicLab.Common/3.3/AsyncHelper.cs
===================================================================
--- /branches/Async/HeuristicLab.Common/3.3/AsyncHelper.cs (revision 15232)
+++ /branches/Async/HeuristicLab.Common/3.3/AsyncHelper.cs (revision 15232)
@@ -0,0 +1,45 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see .
+ */
+#endregion
+
+using System;
+using System.Linq;
+using System.Runtime.ExceptionServices;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace HeuristicLab.Common {
+ public static class AsyncHelper {
+ public static async Task DoAsync(Action startAction, CancellationToken cancellationToken) {
+ try {
+ await Task.Factory.StartNew(
+ ct => startAction((CancellationToken)ct),
+ cancellationToken,
+ cancellationToken,
+ TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+ } catch (OperationCanceledException) {
+ } catch (AggregateException ae) {
+ var e = ae.InnerExceptions.SingleOrDefault() ?? ae;
+ ExceptionDispatchInfo.Capture(e).Throw();
+ }
+ }
+ }
+}
Index: /branches/Async/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
===================================================================
--- /branches/Async/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj (revision 15231)
+++ /branches/Async/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj (revision 15232)
@@ -123,4 +123,5 @@
+
Index: /branches/Async/HeuristicLab.Core/3.3/Engine.cs
===================================================================
--- /branches/Async/HeuristicLab.Core/3.3/Engine.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Core/3.3/Engine.cs (revision 15232)
@@ -22,4 +22,5 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading;
using HeuristicLab.Common;
@@ -90,6 +91,5 @@
} catch (OperationCanceledException) {
} catch (AggregateException ae) {
- if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]);
- else OnExceptionOccurred(ae);
+ OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
} catch (Exception e) {
OnExceptionOccurred(e);
Index: /branches/Async/HeuristicLab.Core/3.3/Executable.cs
===================================================================
--- /branches/Async/HeuristicLab.Core/3.3/Executable.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Core/3.3/Executable.cs (revision 15232)
@@ -93,5 +93,5 @@
public virtual async Task StartAsync() { await StartAsync(CancellationToken.None); }
public virtual async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
public virtual void Pause() {
Index: /branches/Async/HeuristicLab.DebugEngine/3.3/DebugEngine.cs
===================================================================
--- /branches/Async/HeuristicLab.DebugEngine/3.3/DebugEngine.cs (revision 15231)
+++ /branches/Async/HeuristicLab.DebugEngine/3.3/DebugEngine.cs (revision 15232)
@@ -181,6 +181,5 @@
} catch (OperationCanceledException) {
} catch (AggregateException ae) {
- if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]);
- else OnExceptionOccurred(ae);
+ OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
} catch (Exception e) {
OnExceptionOccurred(e);
Index: /branches/Async/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs
===================================================================
--- /branches/Async/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs (revision 15232)
@@ -213,5 +213,5 @@
public virtual async Task StartAsync() { await StartAsync(CancellationToken.None); }
public virtual async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
public virtual void Pause() {
Index: /branches/Async/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs
===================================================================
--- /branches/Async/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs (revision 15232)
@@ -21,4 +21,5 @@
using System;
+using System.Linq;
using System.Threading;
using HeuristicLab.Common;
@@ -69,6 +70,5 @@
} catch (OperationCanceledException) {
} catch (AggregateException ae) {
- if (ae.InnerExceptions.Count == 1) OnExceptionOccurred(ae.InnerExceptions[0]);
- else OnExceptionOccurred(ae);
+ OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
} catch (Exception e) {
OnExceptionOccurred(e);
Index: /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs
===================================================================
--- /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs (revision 15232)
@@ -262,5 +262,5 @@
public async Task StartAsync() { await StartAsync(CancellationToken.None); }
public async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
public void Pause() {
Index: /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs
===================================================================
--- /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs (revision 15232)
@@ -204,5 +204,5 @@
public async Task StartAsync() { await StartAsync(CancellationToken.None); }
public async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
public void Pause() {
Index: /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
===================================================================
--- /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs (revision 15231)
+++ /branches/Async/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs (revision 15232)
@@ -246,5 +246,5 @@
public async Task StartAsync() { await StartAsync(CancellationToken.None); }
public async Task StartAsync(CancellationToken cancellationToken) {
- await Task.Factory.StartNew((ct) => Start((CancellationToken)ct), cancellationToken, cancellationToken);
+ await AsyncHelper.DoAsync(Start, cancellationToken);
}
public void Pause() {