Solved

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

Posted on 2008-10-23
1
7,969 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:dkf360
1 Comment
 

Accepted Solution

by:
dkf360 earned 0 total points
ID: 22791496
I actually found the answer.  In my haste, I forgot to call Timer.Start().
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question