Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/01/16 14:49:02 (7 years ago)
Author:
mkommend
Message:

#2711: Added try/catch/finally blocks in the OnStopped method of algorithms to force the change of the execution state.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r14185 r14433  
    289289    public event EventHandler Stopped;
    290290    protected virtual void OnStopped() {
    291       foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet<object>() { Runs }).OfType<IStatefulItem>()) {
    292         statefulObject.ClearState();
    293       }
    294       runsCounter++;
    295       runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this));
    296       ExecutionState = ExecutionState.Stopped;
    297       EventHandler handler = Stopped;
    298       if (handler != null) handler(this, EventArgs.Empty);
     291      try {
     292        foreach (
     293          IStatefulItem statefulObject in
     294          this.GetObjectGraphObjects(new HashSet<object>() {Runs}).OfType<IStatefulItem>()) {
     295          statefulObject.ClearState();
     296        }
     297        runsCounter++;
     298        try {
     299          runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this));
     300        }
     301        catch (ArgumentException e) {
     302          OnExceptionOccurred(new InvalidOperationException("Run creation failed.", e));
     303        }
     304      }   
     305      finally {
     306        ExecutionState = ExecutionState.Stopped;
     307        EventHandler handler = Stopped;
     308        if (handler != null) handler(this, EventArgs.Empty);
     309      }
    299310    }
    300311    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
Note: See TracChangeset for help on using the changeset viewer.