开发者

M-V-VM and BackgroundWorker

开发者 https://www.devze.com 2023-02-09 12:45 出处:网络
In my app, the BackgroundWorker (housekeeping task) checks for data to be deleted from the database. After the data has been deleted do I then remove that DataItem from the开发者_JAVA技巧 ViewModel or

In my app, the BackgroundWorker (housekeeping task) checks for data to be deleted from the database. After the data has been deleted do I then remove that DataItem from the开发者_JAVA技巧 ViewModel or the Model?

(Yes, I'm new to MVVM and perhaps I don't understand it too well yet).

Thanks.


I'm not sure exactly what you're trying to accomplish, but I would caution about the Background Worker modifying the viewmodel as part it's DoWork method. Modifying the ViewModel suggests a change to the UI, which likely won't work since the DoWork method is not running on the UI thread.


It depends on how your model and your view model are implemented, but conceptually, I'd

  • remove the data from the model, which, in turn, should
    • cause the data to be removed from the database and
    • cause the view models to be notified, so that they can update their state appropriately.
0

精彩评论

暂无评论...
验证码 换一张
取 消