Solved

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

Posted on 2008-10-23
1
7,959 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now