/// <summary> /// Every time the timer ticks we will perform actions based on the Events that were send from the dll /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Timer_Tick(object sender, EventArgs e) { Console.WriteLine($"{_count++} HTE elapsed"); Hotel.PerformAllActions(); // Fix frequent GC calls //Every timer tick we refresh the facility layout _fillFacillityTB(); //Every timer tick we refresh the movable layout _fillMoveAbleTB(); // Disposing the movable bitmap to prevent memory leaking // https://blogs.msdn.microsoft.com/davidklinems/2005/11/16/three-common-causes-of-memory-leaks-in-managed-applications/ _hotelImage.Dispose(); _hotelImage = Hotel.DrawMap(); _hotelBackground.Image = _hotelImage; }
public Simulation(StartupScreen firstScreen, List <JsonModel> layout, SettingsModel Settings) { _options = firstScreen; // 0.5f should be a variable in the Settings data set Hotel = new Hotel(layout, Settings, new JsonHotelBuilder()); this.Settings = Settings; HotelEventManager.HTE_Factor = this.Settings.HTEPerSeconds; //We have a timer that will have a different interval depending on the HTE settings //in order to keep drawing the guest correclty _timer = new Timer { Interval = 1000 / this.Settings.HTEPerSeconds // Specify interval time as you want }; _timer.Tick += new EventHandler(Timer_Tick); _timer.Start(); _hotelImage = Hotel.DrawMap(); //Puts the bitmap on the Picturebox _hotelBackground = new PictureBox { Location = new Point(450, 100), Width = Hotel.HotelWidth * RoomArtSize, Height = Hotel.HotelHeight * RoomArtSize, SizeMode = PictureBoxSizeMode.StretchImage, Image = _hotelImage }; //Adding the picturebox to the form Controls.Add(_hotelBackground); // Last methods for setup InitializeComponent(); _pauseResume = false; pauseBtn.Text = "Pause"; }