Как выполнить событие до таймера? C#
Есть два таймера: Один отсчитывает время от игрового шага до 0, второй вызывает событие Update. Проблема в том, что событие Update выполняется после того, как прошёл первый игровой шаг. Как вызвать событие до таймера и быстро обновить карту?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Timers;
using System.IO;
namespace RTS
{
public partial class Game : Form
{
int time;
int gameSpeed;
Graphics g;
Image grassImage = new Bitmap(Environment.CurrentDirectory + @"\Image\grass.png");
public Game(int countBot, int _gameSpeed)
{
InitializeComponent();
gameSpeed = _gameSpeed;
time = _gameSpeed;
timeLastText.Text = Convert.ToString(_gameSpeed);
System.Windows.Forms.Timer timerLast = new System.Windows.Forms.Timer();
timerLast.Interval = 1000;
timerLast.Tick += new EventHandler(TimeLast);
timerLast.Start();
Thread.Sleep(1000);
System.Windows.Forms.Timer timerGame = new System.Windows.Forms.Timer();
timerGame.Interval = gameSpeed * 1000;
timerGame.Tick += new EventHandler(Update);
timerGame.Start();
}
public void createMap()
{
g = this.CreateGraphics();
this.StartPosition = FormStartPosition.CenterScreen;
g.DrawImage(grassImage, 0, 0, new Rectangle(new Point(0, 0), new Size(360, 360)), GraphicsUnit.Pixel);
}
private void Game_FormClosed(object sender, FormClosedEventArgs e)
{
Environment.Exit(0);
}
public void TimeLast(object sender, EventArgs e)
{
Action action = () =>
{
timeLastText.Text = Convert.ToString(time);
time--;
};
if (InvokeRequired)
{
Invoke(action);
} else
{
action();
}
}
public void Update(object sender, EventArgs e)
{
time = gameSpeed;
createMap();
}
}
}