Using ObservableCollection <T> with Background Streams

Microsoft seems to have had a great idea with an ObservableCollection. They are great for binding and very fast in the user interface.

However, to switch the context to the Dispatcher stream every time you want to configure it seems a bit. Does anyone know the best methods to use them? Is it easy to populate an ICollection as a message object in a business layer and then create an ObservableCollection in the user interface layer? How do you handle collection updates in the user interface?

+6
design-patterns observablecollection
source share
2 answers

Is updating the ObservableCollection in the user interface thread really the reason that most of the bottleneck is for your application? If not, use the update in the user interface thread. Remember that this is not really a context switch that happens when you start something with the Dispatcher - instead, you simply send the task to the user interface thread, which is already a running thread, which the OS will switch to the context in any case moment, the UI thread pulls your submitted job from the internal queue and executes it. You do not force the context switch yourself.

+2
source share

You can use the good old BackgroundWorker also in WPF (as in Windows Forms). It will adapt to the WPF threading model and also provide a good abstraction.

+1
source share

All Articles