Changeset 6445 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/AlgorithmExecutor.cs
- Timestamp:
- 06/20/11 08:56:15 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/AlgorithmExecutor.cs
r6421 r6445 22 22 using System; 23 23 using System.Threading; 24 using HeuristicLab. Optimization;24 using HeuristicLab.Core; 25 25 26 26 namespace HeuristicLab.Problems.MetaOptimization { 27 27 public static class AlgorithmExtensions { 28 public static void StartSync(this I Algorithm algorithm, CancellationToken cancellationToken) {29 var executor = new AlgorithmExecutor( algorithm, cancellationToken);28 public static void StartSync(this IExecutable executable, CancellationToken cancellationToken) { 29 var executor = new AlgorithmExecutor(executable, cancellationToken); 30 30 executor.StartSync(); 31 31 } … … 36 36 /// </summary> 37 37 internal class AlgorithmExecutor { 38 private I Algorithm algorithm;38 private IExecutable executable; 39 39 private AutoResetEvent waitHandle = new AutoResetEvent(false); 40 40 private CancellationToken cancellationToken; 41 41 42 public AlgorithmExecutor(I Algorithm algorithm, CancellationToken cancellationToken) {43 this. algorithm = algorithm;42 public AlgorithmExecutor(IExecutable executable, CancellationToken cancellationToken) { 43 this.executable = executable; 44 44 this.cancellationToken = cancellationToken; 45 45 } 46 46 47 47 public void StartSync() { 48 algorithm.Stopped += new EventHandler(algorithm_Stopped);49 algorithm.Paused += new EventHandler(algorithm_Paused);48 executable.Stopped += new EventHandler(algorithm_Stopped); 49 executable.Paused += new EventHandler(algorithm_Paused); 50 50 51 51 using (CancellationTokenRegistration registration = cancellationToken.Register(new Action(cancellationToken_Canceled))) { 52 algorithm.Start();52 executable.Start(); 53 53 waitHandle.WaitOne(); 54 54 waitHandle.Dispose(); 55 55 } 56 56 57 algorithm.Stopped -= new EventHandler(algorithm_Stopped);58 algorithm.Paused -= new EventHandler(algorithm_Paused);59 if ( algorithm.ExecutionState == Core.ExecutionState.Started) {60 algorithm.Pause();57 executable.Stopped -= new EventHandler(algorithm_Stopped); 58 executable.Paused -= new EventHandler(algorithm_Paused); 59 if (executable.ExecutionState == Core.ExecutionState.Started) { 60 executable.Pause(); 61 61 } 62 62 cancellationToken.ThrowIfCancellationRequested();
Note: See TracChangeset
for help on using the changeset viewer.