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

The Archive Base Latest Questions

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

Right, sticking with the MVVM focus for the minute, there are a small number

  • 0

Right, sticking with the MVVM focus for the minute, there are a small number of scenarios where threading may occur:

As usual, for simplicity we have a Model class, ViewModel class and View class.
The Model has a Collection and a string property.

1) User triggers long running background task. View triggers ViewModel. Can easily be managed by ViewModel using, for example, BackgroundWorker

2) Thread updates Model, ViewModel notified by Model of changes.

Previously we’ve discussed using INotifyChanged to notify changes from Model to ViewModel. The DependencyProperty system appears to marshal these to the correct thread for you.

For ObservableCollections this does not work. Therefore should my model’s public face be single threaded (Don’t like, why should the Model know about threads) or would I replicate some parts of the Model (For example the Collection above) in the ViewModel to ensure that amendments are made on the correct thread?

I think I’ve sort of answered my own question. Perhaps not. My Model does know about threads, so perhaps it’s only polite to markshal them back using the IMarshalInvoker idea mooted earlier by Colin?

Some of my problem here is that I consider MVVM to be yet another MVC variant, and historically I’ve been happy to use terms like MVP, MP, MVC pretty much interchangeably because I knew what worked with the GUI technology (usually winforms) on the V end. When I say MVVM I’m specifically looking for practical advice on what works for WPF and WPF specific foibles. I hope that explains the nature of my questions and why I’m asking them.

  • 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-19T01:27:43+00:00Added an answer on May 19, 2026 at 1:27 am

    I don’t think it’s a very good idea to go all-out and implement collections in your Model as ObservableCollection, as this is “polluting” your Model in a way that’s only useful to WPF.

    INotifyPropertyChanged is OK because:

    • There are many scenarios where having the ability to “listen in” is useful.
    • It can be utilized from pretty much any .NET code, not just WPF.
    • It doesn’t give you any trouble if you want to serialize your Model.

    So, I suggest to not have your model know about threads. Make your ViewModel know about threads, like this:

    class Model {
        List<Widget> Widgets { get; private set; }
    }
    
    class ModelViewModel {
        ObservableCollection<Widget> Widgets { get; private set; }
    
        ModelViewModel(Model model) {
            this.Widgets = new ObservableCollection<Widget>(model.Widgets);
        }
    }
    

    If Widget is a reference type and implements INotifyPropertyChanged (which would be about 100% of the time), this gets you most of the way:

    • Changes to any widget will be made to model itself and will reflect upon bindings immediately
    • Updates to the collection will reflect upon bindings immediately

    There’s still the problem that updates to the collection (adding and removing items) will not be made to model directly. But that can be arranged:

    ModelViewModel(Model model) {
        this.Widgets = new ObservableCollection<Widget>(model.Widgets);
        this.Widgets.CollectionChanged += this.PropagateChangesToModel;
    }
    
    void PropagateChangesToModel(object sender, NotifyCollectionChangedEventArgs e) {
        // do what the name says :)
    }
    

    Finally, you need to make ObservableCollection play well with being updated from a worker thread. This is a really common issue with WPF, and I refer you to the answer to this question for a solution: ObservableCollection and threading.

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

Sidebar

Related Questions

Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now I have a script that will get the last five files in
Right now I have 3 tables: User, Roles, and User_Roles for the many-to-many association.
Right now I have a function, in a class that is used to listen
Right now I came across the Observer/Observable pattern where I have my Observable notify
I was just curious if there was an easy way to display a right
I have a page which I can't seem to get right in terms of
I have a model representing a Content item that contains some images. The number
I want a 'tab' sticking out on the right of the page, that slides

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.