Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2008-10-23
1
Medium Priority
?
8,004 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

972 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