/// <summary> /// This method is called in <see cref="Run">Run</see> method. /// </summary> private void RunThreadFunction() { bool succeed = false; foreach (Model uimodel in _models) { if (_runListener != null) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Calling Prepare() method of model " + uimodel.ModelID; _runListener.OnEvent(theEvent); } uimodel.LinkableComponent.Prepare(); } //Trigger trigger = GetTrigger(); //Debug.Assert(trigger != null); //WHAT THE HELL IS THIS FOR? Thread.Sleep(0); try { // run it !!! // trigger.Run(new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(TriggerInvokeTime))); ITime triggerTime = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(TriggerInvokeTime)); CompositionRunner runner = new CompositionRunner(_models, _runListener); if (Parallelized) { runner.RunParallel(triggerTime, ParallelizeMode); } else { runner.RunSequence(triggerTime); } // close models down if (_runListener != null) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Closing models down..."; _runListener.OnEvent(theEvent); } foreach (Model uimodel in _models) { if (_runListener != null) { string ModelID = uimodel.ModelID; Event theEvent = new Event(EventType.Informative); theEvent.Description = "Calling Finish() on model " + ModelID; _runListener.OnEvent(theEvent); } uimodel.LinkableComponent.Finish(); } // thread finishes - send well known event if (_runListener != null) { _simulationFinishedEvent.Description = "Simulation finished successfuly at " + DateTime.Now.ToString() + "..."; _runListener.OnEvent(SimulationFinishedEvent); } succeed = true; } catch (Exception e) { if (_runListener != null) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Exception occured during simulation: " + e.ToString(); _runListener.OnEvent(theEvent); _simulationFailedEvent.Description = "Simulation FAILED at " + DateTime.Now.ToString() + "..."; _runListener.OnEvent(SimulationFailedEvent); } } finally { endTime = DateTime.Now; var ev = new Event { Description = "Elapsed time: " + (endTime - startTime), Type = EventType.GlobalProgress }; _runListener.OnEvent(ev); _running = false; _runListener = null; // release listener if (AfterSimulationHandler != null) { AfterSimulationHandler(this, succeed); } } }
/// <summary> /// This method is called in <see cref="Run">Run</see> method. /// </summary> private void RunThreadFunction() { bool succeed = false; foreach (Model uimodel in _models) { if (_runListener != null) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Calling Prepare() method of model " + uimodel.ModelID; _runListener.OnEvent(theEvent); } uimodel.LinkableComponent.Prepare(); } //Trigger trigger = GetTrigger(); //Debug.Assert(trigger != null); //WHAT THE HELL IS THIS FOR? Thread.Sleep(0); try { // run it !!! // trigger.Run(new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(TriggerInvokeTime))); ITime triggerTime = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(TriggerInvokeTime)); CompositionRunner runner = new CompositionRunner(_models, _runListener); if (Parallelized) runner.RunParallel(triggerTime, ParallelizeMode); else runner.RunSequence(triggerTime); // close models down if (_runListener != null) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Closing models down..."; _runListener.OnEvent(theEvent); } foreach (Model uimodel in _models) { if (_runListener != null) { string ModelID = uimodel.ModelID; Event theEvent = new Event(EventType.Informative); theEvent.Description = "Calling Finish() on model " + ModelID; _runListener.OnEvent(theEvent); } uimodel.LinkableComponent.Finish(); } // thread finishes - send well known event if (_runListener != null) { _simulationFinishedEvent.Description = "Simulation finished successfuly at " + DateTime.Now.ToString() + "..."; _runListener.OnEvent(SimulationFinishedEvent); } succeed = true; } catch (Exception e) { if (_runListener != null) { Event theEvent = new Event(EventType.Informative); theEvent.Description = "Exception occured during simulation: " + e.ToString(); _runListener.OnEvent(theEvent); _simulationFailedEvent.Description = "Simulation FAILED at " + DateTime.Now.ToString() + "..."; _runListener.OnEvent(SimulationFailedEvent); } } finally { endTime = DateTime.Now; var ev = new Event { Description = "Elapsed time: " + (endTime - startTime), Type = EventType.GlobalProgress }; _runListener.OnEvent(ev); _running = false; _runListener = null; // release listener } if (AfterSimulationHandler != null) { AfterSimulationHandler(this, succeed); } }