Update BindingList<> from a background Thread?

↘锁芯ラ 提交于 2019-12-10 17:42:26

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3587032/update-bindinglist-from-a-background-thread

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!