Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 945
Houman Avatar asked Aug 01 '26 08:08

Houman


1 Answers

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.

like image 164
Stephen Cleary Avatar answered Aug 03 '26 00:08

Stephen Cleary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!