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

  • Home
  • SEARCH
  • 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 6960515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:24:42+00:00 2026-05-27T15:24:42+00:00

I have implemented a DispatcherTimer with databinding which would act like a stopwatch or

  • 0

I have implemented a DispatcherTimer with databinding which would act like a stopwatch or counting timer to display the time elapsed during an audio call. (as you can see in your mobile phones)

The following code is becoming slow for every minute by “1 second” which is not good in calculating the bill. Can you please tell me where I am wrong ?

System.Windows.Threading.DispatcherTimer dispatcherTimer; 
int seconds = 0;
public string Counter { get; set; }
public Timer()
    {
        InitializeComponent();
        this.DataContext = this;
        dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
        dispatcherTimer.Interval = new TimeSpan(0, 0, 1);         
    }
  private void dispatcherTimer_Tick(object sender, EventArgs e)
    {

       Counter = (seconds / 3600).ToString() + ":" + (seconds / 60).ToString("00") + ":" + (seconds % 60).ToString("00");
       NotifyPropertyChanged("Counter");
       seconds++;
    }

I compared this timer with other stop watches both in Internet and also in mobile, this timer is getting delayed by a second for each minute.

  • 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-27T15:24:43+00:00Added an answer on May 27, 2026 at 3:24 pm

    You are relying on the timer, and it seems to be consistently inaccurate by the same amount.

    Why don’t you take a point in time and store that,

    private DateTime startTime;
    
    public Timer()
    {
        InitializeComponent();
        startTime = DateTime.Now;
    }
    
    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        Counter = (DateTime.Now - startTime).ToString();
        ...
    }
    

    Actually taking the code like this shows why you are having a problem. The ToString method there shows the counter more accurately including milliseconds, and it turns out the timer is not firing every 1 second, but more like every 1.01 seconds.

    I am getting values like this,

    1.008
    1.02
    1.031
    1.03901
    

    etc.

    You can then replace the above with this,

    private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan elapsedTime = (DateTime.Now - startTime);
            Counter = string.Format("{0:hh\\:mm\\:ss}", elapsedTime);
    

    And it will be formatted like you had it before with no milliseconds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented a simple linked list class and I would now like to
I have implemented an XMLHttpRequest() call to a standalone html page which simply has
I have implemented below function in a separate .js script file which I load
i have implemented galleryview in one screen named display_image.xml in which i have shown
I have implemented cloaking for search engines. In my category pages, it will display
I have implemented a REST Webservice which returns (after an authentication via RFC 2617
I have implemented a multi-threaded program which involves spawning a thread for each user,and
I have implemented button which clicks and opens dialog with spinner inside as described
I have implemented a custom designer class which inherits from DocumentDesigner. The standard Form
I have implemented software which have a DLL library which contains a set of

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.