Changeset 15721 for branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
- Timestamp:
- 02/04/18 22:33:26 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs
r15605 r15721 214 214 215 215 private void Initialize() { 216 timer = new System.Timers.Timer();217 timer.Interval = 50;218 timer.Elapsed += Timer_Elapsed;219 216 if (algorithm != null) RegisterAlgorithmEvents(); 220 217 snapshotTimes.ItemsAdded += snapshotTimes_Changed; … … 258 255 } 259 256 260 private System.Timers.Timer timer;261 262 private void Timer_Elapsed(object sender, EventArgs e) {263 if (Algorithm.ExecutionState == ExecutionState.Started) {264 if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex]265 && !pausedForSnapshot) {266 pausedForSnapshot = true;267 Algorithm.Pause();268 }269 if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) {270 pausedForTermination = true;271 if (!pausedForSnapshot) Algorithm.Pause();272 }273 }274 }275 276 257 #region Events 277 258 protected override void OnNameChanged() { … … 292 273 if (handler != null) handler(this, EventArgs.Empty); 293 274 } 294 [Obsolete("Deprecated needs to be removed")]295 275 public event EventHandler ExecutionTimeChanged; 276 private void OnExecutionTimeChanged() { 277 var handler = ExecutionTimeChanged; 278 if (handler != null) handler(this, EventArgs.Empty); 279 } 296 280 public event EventHandler Prepared; 297 281 private void OnPrepared() { … … 301 285 public event EventHandler Started; 302 286 private void OnStarted() { 303 timer.Start();304 287 var handler = Started; 305 288 if (handler != null) handler(this, EventArgs.Empty); … … 307 290 public event EventHandler Paused; 308 291 private void OnPaused() { 309 timer.Stop();310 292 var handler = Paused; 311 293 if (handler != null) handler(this, EventArgs.Empty); … … 313 295 public event EventHandler Stopped; 314 296 private void OnStopped() { 315 timer.Stop();316 297 var handler = Stopped; 317 298 if (handler != null) handler(this, EventArgs.Empty); … … 327 308 private void RegisterAlgorithmEvents() { 328 309 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 310 algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged; 329 311 algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged; 330 312 algorithm.Paused += Algorithm_Paused; … … 335 317 private void DeregisterAlgorithmEvents() { 336 318 algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred; 319 algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged; 337 320 algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged; 338 321 algorithm.Paused -= Algorithm_Paused; … … 343 326 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 344 327 OnExceptionOccurred(e.Value); 328 } 329 private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) { 330 if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex] 331 && !pausedForSnapshot) { 332 pausedForSnapshot = true; 333 Algorithm.Pause(); 334 } 335 if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) { 336 pausedForTermination = true; 337 if (!pausedForSnapshot) Algorithm.Pause(); 338 } 339 OnExecutionTimeChanged(); 345 340 } 346 341 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.