Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/19/11 10:48:07 (12 years ago)
Author:
svonolfe
Message:

Refactored solution (#1610)

Location:
branches/SimulationCore/HeuristicLab.SimulationCore/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3

    • Property svn:ignore
      •  

        old new  
        33bin
        44obj
         5Plugin.cs
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/Simulation.cs

    r6623 r7204  
    7777    }
    7878
    79     public override void Start() {
     79    private class RunInformation {
     80      public CancellationTokenSource CancellationToken { get; set; }
     81      public IExecutionContext ExecutionContext { get; set; }
     82    }
     83
     84    public virtual void Start(IExecutionContext executionContext) {
    8085      base.Start();
     86
     87      RunInformation runInfo = new RunInformation();
    8188      cancellationTokenSource = new CancellationTokenSource();
     89      runInfo.CancellationToken = cancellationTokenSource;
     90      runInfo.ExecutionContext = executionContext;
    8291      stopPending = false;
    83       Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token);
     92      Task task = Task.Factory.StartNew(Run, runInfo, runInfo.CancellationToken.Token);
    8493      task.ContinueWith(t => {
    8594        try {
     
    100109        else OnPaused();
    101110      });
     111    }
     112
     113    public override void Start() {
     114      Start(null);     
    102115    }
    103116    protected override void OnStarted() {
     
    131144
    132145    private void Run(object state) {
    133       CancellationToken cancellationToken = (CancellationToken)state;
     146      RunInformation runInfo = (RunInformation)state;
    134147
    135148      OnStarted();
     
    140153      timer.Start();
    141154      try {
    142         Run(cancellationToken);
     155        foreach (IParameter parameter in Parameters) {
     156          parameter.ExecutionContext = runInfo.ExecutionContext;
     157        }
     158
     159        Run(runInfo.CancellationToken.Token);
    143160      }
    144161      finally {
     
    146163        timer.Stop();
    147164        ExecutionTime += DateTime.Now - lastUpdateTime;
     165
     166        foreach (IParameter parameter in Parameters) {
     167          parameter.ExecutionContext = null;
     168        }
    148169      }
    149170      Stop();
    150171
    151       cancellationToken.ThrowIfCancellationRequested();
     172      runInfo.CancellationToken.Token.ThrowIfCancellationRequested();
    152173    }
    153174    protected abstract void Run(CancellationToken cancellationToken);
Note: See TracChangeset for help on using the changeset viewer.