更新的BindingList<>从后台线程?线程、后台、BindingList、LT

2023-09-05 02:09:28 作者:几度轮回゛却未寻回你づ

我不知道我怎么会使用调度员在WPF安全地从另一个线程更新我的BindingList集合?

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,

非常感谢, 卡瓦

推荐答案

我preFER调度工作到UI线程。你可以通过调用拿到UI线程调度 TaskScheduler.FromCurrentSynchronizationContext ,而在UI线程上。 MSDN有一个例子这里 。

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.

我一般是preFER 的SynchronizationContext 为基础的解决方案,而不是调度为基础的解决方案,因为它们不依赖到WPF / Silverlight的。因此,有可能编写处理还可以从WPF,ASP.NET,Windows窗体,Win32的服务,等等。

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.

 
精彩推荐