Background thread progress notification in MVVM? Background thread progress notification in MVVM? multithreading multithreading

Background thread progress notification in MVVM?


Since the property is a simple property (and not a collection), you should be able to set it directly. WPF will handle the marshaling back to the UI thread automatically.

However, in order to avoid a race condition, you'll need to handle the incrementing of your "done" counter explicitly. This could be something like:

private object DoWork(string[] fileList, ProgressDialogViewModel viewModel){    int done; // For proper synchronization    Parallel.ForEach(fileList,        imagePath =>        {           ProcessImage(imagePath));           Interlocked.Increment(ref done);           viewModel.Progress = done;       }}