Menu

Does the Simulation.Stop() work?

Help
2006-08-06
2013-04-23
  • Guido Broghammer

    I think, the Simulation.Stop() function does not work correctly. After some debugging I registered, that the _currentTime variable is always 0. Is this correct? Do I have to initialize the Timer? Thanks for help.

     
    • Eric Roe

      Eric Roe - 2006-08-13

      Guido,

      Simulation.Stop() does work, but possibly not as you might expect.  Stop() tells the simulation to terminate at the current time but only AFTER processing all the events scheduled at the current time.  Hence if the current time is T, then all events scheduled at time T will run and the simulation will end only if an attempt is made to advance the clock past time T.

      This behavior is probably a bit counterintuitive, and is something I'm seriously considering changeing.  I think it might be preferable if a stop time is set to time T, no events at time T or beyond are run.

      As for why the _currentTime instance variable is always zero (0), that's probably because you're never advancing the clock.  For the clock to be advanced, the Task.Activate(object activator, long relTime, object data, int priority) method must be invoked (possibly via one of the other Task.Activate implementations) with the relTime parameter set to a value greater than zero.  If each task activation is scheduled at a relative time zero time units from the current time, the clock will never advance and the current simulation time will always be zero.

       

Log in to post a comment.