Feed a ViewModel with massive Data coming from a different Thread
Posted: 14 Feb 2023, 12:16
Hey everyone,
we've set up Noesis in a way that it lives on its own thread. Nevertheless, the data it has to display comes from a different thread. So, how can we access the data without locking the database for a long time? Executing the OnPropertyChanged event for hundreds of elements in a ViewModel and refreshing the layout will take its time.
My naive attempt is to implement a queue between the threads that swaps out multiple versions of the ViewModel:
So the database accesses and writes to ViewModel A. When an update is finished, ViewModel A gets swapped with ViewModel B, and the database thread can already release the lock, freeing up the thread to continue its duty. In the meanwhile, the UI-thread can execute all the layout work and OnPropertyChanged events with the data it got.
In practice, I am not sure what Noesis' reflection system has to say about the fact that its underlying ViewModel is exchanged all the time. But I fear that it is not doable. To implement the OnPropertyChanged event in the first place, I need to derive from Noesis::BaseComponent. But BaseComponent has its copy-constructor explicitly deleted. Therefore, I cannot execute std::swap on such a ViewModel. Which prevents me to implement a queue with the ViewModel itself.
Leaving me with the questions:
- Am I right in the assumption that I cannot swap a registered ViewModel?
- What would your approach be in such a situation?
we've set up Noesis in a way that it lives on its own thread. Nevertheless, the data it has to display comes from a different thread. So, how can we access the data without locking the database for a long time? Executing the OnPropertyChanged event for hundreds of elements in a ViewModel and refreshing the layout will take its time.
My naive attempt is to implement a queue between the threads that swaps out multiple versions of the ViewModel:
So the database accesses and writes to ViewModel A. When an update is finished, ViewModel A gets swapped with ViewModel B, and the database thread can already release the lock, freeing up the thread to continue its duty. In the meanwhile, the UI-thread can execute all the layout work and OnPropertyChanged events with the data it got.
In practice, I am not sure what Noesis' reflection system has to say about the fact that its underlying ViewModel is exchanged all the time. But I fear that it is not doable. To implement the OnPropertyChanged event in the first place, I need to derive from Noesis::BaseComponent. But BaseComponent has its copy-constructor explicitly deleted. Therefore, I cannot execute std::swap on such a ViewModel. Which prevents me to implement a queue with the ViewModel itself.
Leaving me with the questions:
- Am I right in the assumption that I cannot swap a registered ViewModel?
- What would your approach be in such a situation?