It seems like Microsoft had a great idea with the ObservableCollection. They are great for binding, and are super fast on the UI.
However, requiring a context switch to the Dispatcher Thread every time you want to tweak it seems like a bit much. Does anyone know the best practices for using them? Is it simply to populate an ICollection as a message object in the business layer, then create the ObservableCollection in the UI layer? How do you then handle updates to the collection on the UI?
Is updating the ObservableCollection on the UI thread really causing that much of a bottleneck for your application? If not, stick with updating it on the UI thread. Remember, it's not really a context switch that's happening when you run something with the Dispatcher - instead, you're simply submitting a job to the UI thread, which is an already running thread, which the OS will context switch to at some point anyway. The UI thread pulls your submitted job off of an internal queue and executes it. You're not forcing the context switch yourself.
You can use good old BackgroundWorker also in WPF (as in Windows Forms). It will adopt to the threading model of WPF and also provide a nice abstraction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With