I've set up my timer as such and it works fine. However I need the interval to fire more frequently so that the clock counts down quicker (as it wouldn't be appropriate for the user to have wait for the timer to countdown in real time, as it is a simulation). I hope I've explained it appropriately, please ask if you have any questions. Any help would be very much appreciated!
System.Windows.Forms.Timer timer;
TimeSpan countdownClock = TimeSpan.Zero;
private void Form1_Load(object sender, EventArgs e)
{
timer = new System.Windows.Forms.Timer(); //Initialise timer
timer.Interval = (int)TimeSpan.FromSeconds(1).TotalMilliseconds;
timer.Tick += OnTimeEvent;
DisplayTime();
}
private void DisplayTime()
{
lblTime.Text = countdownClock.ToString(@"hh\:mm\:ss"); //Define timer
}
private void OnTimeEvent(object sender, EventArgs e)
{
countdownClock = countdownClock.Subtract(TimeSpan.FromMilliseconds(timer.Interval)); //Set up countdown
if (countdownClock.TotalMilliseconds <= 0)
{
countdownClock = TimeSpan.Zero;
timer.Stop();
Button_Open.Enabled = true;
}
DisplayTime();
}