Link to home
Start Free TrialLog in
Avatar of dkf360
dkf360

asked on

How to create a countdown timer in a Visual C# windows app?

Hi,
I want to create a timer to count down from the current time to the next hour.  For example, it's format will look like this: 59:59, 59:58, 59:57... to 00:00, which I will then execute a timed method.

The problem is, I don't know how to do this.  Here's the code I've hacked up thus (removed code irrelevant to this discussion), far, but the label doesn't seem to be refreshing, so the timer being displayed is not counting down:

        private void Form1_Load(object sender, EventArgs e)
        {
            exeTimer.Interval = 1000;
            exeTimer_Tick(this, EventArgs.Empty);  
        }

        private void exeTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan sp = new TimeSpan(0, 60 - DateTime.Now.Minute, 60 - DateTime.Now.Second);
            lblExecution.Text = string.Format("Time to Execution: {0}:{1:00}", sp.Minutes, sp.Seconds);
        }

I know I'm missing more code to make this complete.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of dkf360
dkf360

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial