Call NotifyOfPropertyChange in a different thread?
See original GitHub issueIs it possible to call NotifyOfPropertyChange
from a different thread?
I have a ViewModel
class with a method called LoadData()
which calls NotifyOfPropertyChange
for all variables in that class.
I also have a class which uses C#s Timer class to run a background method every 1 minute which fetches new data from DB. This method calls the LoadData
method in the ViewModel
class. But it does not refresh the UI. Should the LoadData
method be called only from the UI thread?
Here are my classes:
public class ShellViewModel : Conductor<object>
{
public List<MyClass> AllData {get; set;}
public void LoadData()
{
NotifyOfPropertyChange(() => AllData);
}
}
My Timer Class
public class RecurringTasks : PropertyChangedBase
{
//This method runs in a background thread
private void UpdateData()
{
//Code to connect to DB and get data
_shellViewModel.AllData = //assign data from DB
_shellViewModel.LoadData();
}
Whenever the Timer runs the UpdateData() method, I see that the data in the “AllData” field ShellViewModel actually gets updated. But the UI is not changing.
Issue Analytics
- State:
- Created 4 years ago
- Comments:19 (10 by maintainers)
Top Results From Across the Web
WPF and NotifyPropertyChanged from a different thread
It looks like moreless I've found the answer for this specific situation. The exception is not thrown by UiModel and it's binding, but...
Read more >How to trigger [NotifyPropertyChanged] from background ...
In this case the OnPropertyChanged method is called on worker thread because the StartTogglingAsync method has been started on the worker thread by...
Read more >Category Model and ViewModel
The NotifyOfPropertyChange method cannot look inside it to see if the contents has changed. To solve this, the contents is removed and completely...
Read more >ObservableProperty attribute - .NET Community Toolkit
The first two are useful whenever you want to run some logic that only needs to reference the new value that the property...
Read more >Caliburn Micro Part 2: The Basics of Databinding - System.Mike!
PropertyChangedBase gives us access to NotifyOfPropertyChange which tells the view that it should display the new value every time the Message ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That would work but could have side effects in other areas of your application.
I’m going to close this issue out as it’s definitely not a framework bug.
Thanks. Making all ViewModels as Singletons worked and there were no other issues in the application. Its because, I always though all ViewModels would be singleton by default and wrote code accordingly.