views:

843

answers:

2

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?

+2  A: 

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.

unforgiven3
It is not a context switch unless it is a synchronous operation
Veer
It's always a context switch when the OS moves from thread to thread, what do you mean "unless it is a synchronous operation"?
unforgiven3
+1  A: 

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.

huseyint