Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-23
1
Medium Priority
?
7,997 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

704 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