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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:22:12+00:00 2026-05-18T01:22:12+00:00

Not being experienced in multi-threaded programming or technologies, I would like to ask this

  • 0

Not being experienced in multi-threaded programming or technologies, I would like to ask this question as a way to focus a design to accomplish the following requirements for relatively long running jobs (between 4 and 10 seconds) that are launched in real time by some user action:

  1. After the job is initiated and until it completes:
      * Show some indeterminate progress indicator (ie, spinning ball, progress bar)
      * Show a running count of the elapsed number of seconds as part of a status update
  2. Use an MVVM design with the status and notion of IsBusy being data bound properties in some INPC view model class
  3. Unit testable

I started down the path of trying to use a BackgroundWorker that is either subclassed or otherwise encapsulated, but found myself getting tripped up on how to synchronize the notion of counting the elapsed seconds on a timer thread while another thread is doing the work.

Design ideas that might lead to more focused programming questions much appreciated!

Cheers,
Berryl

  • 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-18T01:22:13+00:00Added an answer on May 18, 2026 at 1:22 am

    Use a DispatcherTimer to update a ElapsedTime property in your view model. This is called from the GUI thread so you can directly bind to the property. Use a BackgroundWorker to perform your thread task.

    public class ViewModel : INotifyPropertyChanged  
    {
      public DateTime ElapsedTime {get; private set;}
      public bool IsRunning {get; private set;}
    
      private BackgroundWorker worker = new BackgroundWorker();
      private DateTime startTime;
      private DispatcherTimer t = new DispatcherTimer();
    
      public ViewModel()
      {
        t.Interval = 500; 
        t.Tick += (ox,ex) => UpdateTime();
        worker.DoWork += YourMethodHere;
        worker.RunWorkerCompleted += (ox,ex)=> {
          IsRunning = false;
          if (PropertyChanged != null)
           PropertyChanged(this, new PropertyChangedEventArgs("IsRunning"));
        };
      }
    
      public void UpdateTime()
      {
         ElapsedTime=startTime.Subtract(DateTime.Now);
         if (PropertyChanged != null)
           PropertyChanged(this, new PropertyChangedEventArgs("ElapsedTime"));
      }
    
      public void Start()
      {
        startTime=DateTime.Now;
        worker.RunWorkerAsync();
        IsRunning = true;
        if (PropertyChanged != null)
         PropertyChanged(this, new PropertyChangedEventArgs("IsRunning"));
      }
    

    }

    You can bind the progress bar GUI element to a bool property in your view model which is updated when started and finishing your background task (use the RunWorkerComplete event).

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

Sidebar

Related Questions

No related questions found

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.