问题
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