Exemple #1
0
    /// <summary>
    /// Runs event loop till either current time is greater than passed endTime or there are no more scheduled events.
    /// </summary>
    /// <param name="endTime">Simulation time indicating when to stop simulation.</param>
    public static void Run()
    {
        whenStarted = DateTime.Now;
        const string progressText = "Simulating.";
        ProgressLogger.Starting(progressText);
        ProgressLogger.Progress();
        lastShown = DateTime.Now;
        while(events.Count>0 && currentTime <= simulationTime)
        {
            //show progress
            if (lastShown + showingDelay < DateTime.Now)
            {
                ProgressLogger.Progress();
                lastShown = DateTime.Now;
            }
            ++loopNumber;

            //next event;

            TimerEntryImplementation entry = events.DeleteMin();
            currentTime = entry.Time;
            entry.Method(entry);
        }
        if (events.Count == 0)
        {
            Console.WriteLine("No more events to handle.");
        }
        if (currentTime > simulationTime)
        {
            Console.WriteLine("Simulation came to its end time.");
        }
        ProgressLogger.Finished(progressText);
    }