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:
- 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
- Use an MVVM design with the status and notion of IsBusy being data bound properties in some INPC view model class
- 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
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.
}
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).