Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8170


Ignore:
Timestamp:
06/30/12 18:09:56 (12 years ago)
Author:
gkronber
Message:

#1878: added synchronization to all event handlers for optimizer events in the Experiment

File:
1 edited

Legend:

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

    r8136 r8170  
    326326      optimizer.Runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(optimizer_Runs_ItemsRemoved);
    327327    }
     328
     329    private readonly object locker = new object();
    328330    private void optimizer_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    329       OnExceptionOccurred(e.Value);
     331      lock (locker)
     332        OnExceptionOccurred(e.Value);
    330333    }
    331334    private void optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
    332       ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
     335      lock (locker)
     336        ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
    333337    }
    334338    private void optimizer_Paused(object sender, EventArgs e) {
    335       if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) OnPaused();
     339      lock (locker)
     340        if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) OnPaused();
    336341    }
    337342    private void optimizer_Prepared(object sender, EventArgs e) {
    338       if (Optimizers.All(x => x.ExecutionState == ExecutionState.Prepared)) OnPrepared();
     343      lock (locker)
     344        if (Optimizers.All(x => x.ExecutionState == ExecutionState.Prepared)) OnPrepared();
    339345    }
    340346    private void optimizer_Started(object sender, EventArgs e) {
    341       if (ExecutionState != ExecutionState.Started) OnStarted();
    342     }
    343 
    344     private readonly object locker = new object();
     347      lock (locker)
     348        if (ExecutionState != ExecutionState.Started) OnStarted();
     349    }
    345350    private void optimizer_Stopped(object sender, EventArgs e) {
    346351      lock (locker) {
     
    356361    }
    357362    private void optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    358       Runs.RemoveRange(e.OldItems);
    359       Runs.AddRange(e.Items);
     363      lock (locker) {
     364        Runs.RemoveRange(e.OldItems);
     365        Runs.AddRange(e.Items);
     366      }
    360367    }
    361368    private void optimizer_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    362       Runs.AddRange(e.Items);
     369      lock (locker)
     370        Runs.AddRange(e.Items);
    363371    }
    364372    private void optimizer_Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    365       Runs.RemoveRange(e.Items);
     373      lock (locker)
     374        Runs.RemoveRange(e.Items);
    366375    }
    367376
Note: See TracChangeset for help on using the changeset viewer.