Changeset 6018 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/AlgorithmExecutor.cs
- Timestamp:
- 04/17/11 18:22:28 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/AlgorithmExecutor.cs
r5653 r6018 10 10 executor.StartSync(); 11 11 } 12 public static void StartSync(this IAlgorithm algorithm, CancellationToken cancellationToken) { 13 var executor = new AlgorithmExecutor(algorithm, cancellationToken); 14 executor.StartSync(); 15 } 12 16 } 13 17 … … 18 22 private IAlgorithm algorithm; 19 23 private AutoResetEvent waitHandle = new AutoResetEvent(false); 24 private CancellationToken cancellationToken; 25 private bool useCancellationToken = false; 20 26 21 27 public AlgorithmExecutor(IAlgorithm algorithm) { … … 23 29 } 24 30 31 public AlgorithmExecutor(IAlgorithm algorithm, CancellationToken cancellationToken) { 32 this.algorithm = algorithm; 33 this.cancellationToken = cancellationToken; 34 this.useCancellationToken = true; 35 } 36 25 37 public void StartSync() { 26 38 algorithm.Stopped += new EventHandler(algorithm_Stopped); 27 39 algorithm.Paused += new EventHandler(algorithm_Paused); 28 algorithm.Start(); 40 41 if(useCancellationToken && algorithm is EngineAlgorithm && ((EngineAlgorithm)algorithm).Engine is SequentialEngine.SequentialEngine) { 42 ((SequentialEngine.SequentialEngine)((EngineAlgorithm)algorithm).Engine).Start(cancellationToken); 43 } else { 44 algorithm.Start(); 45 } 46 29 47 waitHandle.WaitOne(); 30 48 waitHandle.Dispose();
Note: See TracChangeset
for help on using the changeset viewer.