I am in a process of extending ObservableCollection<T>
, which will notify collection change back to UI thread from ViewModel
in an ideal MVVM
scenario. To achieve this, I am thinking of resolving UI Dispatcher
through some IOC
and eventually use the resolved Dispatcher
instance within my custom observable type.
Draft will look like this;
class SafeObservableCollection<T>: ObservableCollection<T>
{
public SafeObservableCollection(IDispatcher currentDispatcher)//maybe an instance of Dispatcher
{
//assign resolved dispatcher to a private member
}
}
Assumption: (a) WPF application which uses one Dispatcher/UIThread. (b) I am not thinking of any deviation (APM/EPM using BackgroundWorker) apart from overriding base class members of ObservableCollection
Question: Can you propose anything better to resolve Dispatcher instance while following the outlined code? Can you help me to nail down any possible design flaw? Such as memory leak, deadlock or anything which I overlooked. What should be / would be the lifetime of my Dispatcher instance if I decided to go with this approach.