Search code examples
.netmultithreadingdispatcherbindinglist

Update BindingList<> from a background Thread?


I was wondering how I would use the Dispatcher in WPF to safely update my BindingList collection from another thread?

I am also open for other solutions,

Many Thanks, Kave


Solution

  • I prefer scheduling a Task to the UI thread. You can get the UI thread scheduler by calling TaskScheduler.FromCurrentSynchronizationContext while on the UI thread. MSDN has an example here.

    I generally prefer SynchronizationContext-based solutions instead of Dispatcher-based solutions because they are not tied to WPF/Silverlight. So, it's possible to write a common business object layer that handles the synchronization yet can be used from WPF, ASP.NET, Windows Forms, Win32 Services, etc.