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 7813745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:58:36+00:00 2026-06-02T04:58:36+00:00

I am trying to have a label display the time it takes the user

  • 0

I am trying to have a label display the time it takes the user to complete a task which starts at 00:00:00 and goes up in shown millisecond increments from there.
So far I have this:

    private void startTimer()
    {
        stopWatch.Start();
        Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(ShowElapsedTime));
    }
    void ShowElapsedTime()
    {
        TimeSpan ts = stopWatch.Elapsed;
        lblTime.Text = String.Format("{0:00}:{1:00}.{2:00}", ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
    }

startTimer(); is called on a button click

Can someone point me in the right direction?

  • 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-06-02T04:58:36+00:00Added an answer on June 2, 2026 at 4:58 am

    I’d recommend taking an MVVM approach. Have your TextBlock bind to a string member on your ViewModel. In your ViewModel you can use a DispatcherTimer to set the the time elapsed. The DispatcherTimer fires its callback on the UI thread so you don’t need to invoke to the UI thread.

    Code:

    public class ViewModel : INotifyPropertyChanged
    {
         public event PropertyChangedEventHandler PropertyChanged;
         public string TimeElapsed {get;set;}
    
         private DispatcherTimer timer;
         private Stopwatch stopWatch;
    
         public void StartTimer()
         {
              timer = new DispatcherTimer();
              timer.Tick += dispatcherTimerTick_;
              timer.Interval = new TimeSpan(0,0,0,0,1);
              stopWatch = new Stopwatch();
              stopWatch.Start();
              timer.Start();
         }
    
    
    
         private void dispatcherTimerTick_(object sender, EventArgs e)
         {
             TimeElapsed = stopWatch.Elapsed.TotalMilliseconds; // Format as you wish
             PropertyChanged(this, new PropertyChangedEventArgs("TimeElapsed")); 
         }
    }
    

    XAML:

    <TextBlock Text="{Binding TimeElapsed}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a label display single-digit numbers as double-digit numbers (ie.
I'm trying to get wxCheckBox to have sensitive label like it is in some
Trying to use GridBagLayout. I have the method called buildLabel. This creates three label.
I'm trying to have 'help' tooltips which appear when you click on labels of
Afternoon, I am trying have an HTML file containing a frameset which contains two
I have a cache directory I'm trying to have ignored by git which lives
What I am trying to accomplish is to have checkbox labels display after checkbox
I am trying to create a stop watch type functionality. I have one label
I have been trying to play around with this for a long time and
After a long time of trying things I still not have come any closer,

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.