Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:42:55+00:00 2026-05-31T11:42:55+00:00

I have an application that requires multiple countdown timers to run (some simultaneously). They

  • 0

I have an application that requires multiple countdown timers to run (some simultaneously). They also update UI elements with the time remaining on the countdown. I have tried using DispatcherTimer for it’s easy way to interact with UI elements. However, over a 300 second countdown, it becomes out of sync with real time (because of the heavy UI updating) to the point that I get 30 seconds left on the timer when it should be 0.

I then tried switching to a System.Threading.Timer (code below). Now, the timer is spot-on and in sync with real life time. However, the Timer stops ticking after a random number of ticks (between 3 seconds and 60 seconds). I suspect it’s either the garbage collector kicking in, or the Invoke (used for updating the UI) but don’t really have the knowledge to continue down this path. Can anybody give me any insight as to why the timer randomly stops ?

private int counter = 500;    
private void btnTopBlue_Click(object sender, RoutedEventArgs e)
{
    btnTopBlue.Content = counter.ToString();
    Timer dt = new Timer(topBlue_Tick, null, 1000, 1000);
}
private void topBlue_Tick(object sender)
{
     if (counter > 0)
     {
         counter--;
         Dispatcher.BeginInvoke(() => btnTopBlue.Content = counter.ToString());    
     }
     else
         ((Timer)sender).Dispose();
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:42:57+00:00Added an answer on May 31, 2026 at 11:42 am

    Don’t count. Compare current time to the start time of the timer, and do the math. That way, even if you miss a half second here and a half second there, you’ll still be spot on time.

    Consider this code:

        private static DateTime EndTime { get; set; }
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
    
            DispatcherTimer dt = new DispatcherTimer();
            dt.Interval = TimeSpan.FromSeconds(.1);
    
    
            dt.Tick += (s, evt) =>
                           {
                               var remaining = EndTime - DateTime.Now;
    
                               timeRemaining.Text = string.Format("{0:0.0}", remaining.TotalSeconds);
    
                               if(remaining.TotalSeconds <= 0)
                               {
                                   dt.Stop();
                               }
                           };
    
            EndTime = DateTime.Now + TimeSpan.FromSeconds(30);
            dt.Start();
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have VB application that requires visual service pack 6 to run , now
I have a script that calls an application that requires user input, e.g. run
I have a Tomcat application that requires multiple passwords on startup. My current configuration
I have an existing python application (limited deployment) that requires the ability to run
I have an application that requires .Net. I have found out how to check
I have an application that requires the user to reenter their password between 15
I have an application that requires resizing of a component that will be scaled
I have an application that requires Microsoft VC++ 2005 (SP1) Redistributable Package. I know
We have a new application that requires glibc 2.4 (from gcc 4.1). The machine
I have a c# wpf application that requires SQL Express 2005 database and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.