Hello, I have created a timer for my Winforms to tick down from 300 to 0 and then refresh my form. I have used this.refresh when it hits 0 but it doesn't seem to do anything as the label is still the same when it has completed it's timer function. Any ideas how to get it to work?

// Start the timer.
            timeLeft = 300;            
            timer1.Start();

 private void timer1_Tick(object sender, EventArgs e)
        {        
            if (timeLeft > 0)
            {
                timeLeft = timeLeft - 1;
                lblTime.Text = timeLeft + " seconds";
            }
            else if (timeLeft == 0)
            {
                //Timer runs out of time and refresh form
                RefreshDirSize1();
                RefreshDirSize2();
                RefreshDirSize3();
                RefreshDirSize4();
                this.Refresh();
            }

Please use code tags if you post code.
What label are you talking about?
else if (timeLeft == 0) is a bit meaningless, you can just as well say else

lblTime.Text....

I have come up with a solution but not sure if it is sound coding but it works.. I have put TimeLeft = 300 again, when the timer hits 0 so it goes back to 300.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.