';系统.反应式.并发.调度程序.NewThread';已过时

本文关键字:过时 NewThread 反应式 系统 并发 调度程序 | 更新日期: 2023-09-27 17:59:32

我正在尝试使用Entity Framework 5.0代码快速响应扩展(Rx)从数据库中检索数据。我正在为此编写以下代码。

var obs = DataContext.GetDataContext().BreakdownCauses.OrderBy(x => x.Cause).ToObservable(Scheduler.NewThread);
obs.SubscribeOnDispatcher().Subscribe(x => ItemCollection.Add(slow(x))); 
BreakdownCause slow(BreakdownCause cs)
    {
        System.Threading.Thread.Sleep(500);
        return cs;
    }

但它向我展示了这个警告:

'System.Reactive.Concurrency.Scheduler.NewThread' is obsolete: 'This property is no longer supported due to refactoring of the API surface and elimination of platform-specific dependencies. Please add a reference to the System.Reactive.PlatformServices assembly for your target platform and use NewThreadScheduler.Default to obtain an instance of this scheduler type. See http://go.microsoft.com/fwlink/?LinkID=260866 for more information.'

在运行时,我得到一个例外:

The calling thread cannot access this object because a different thread owns it.

请建议我如何在我的WPF应用程序中快速地在EF5.0代码中正确使用Reactive Extensions(Rx),或者以任何更好的方式异步调用数据库。

';系统.反应式.并发.调度程序.NewThread';已过时

您需要调用ObserveOnDispatcher而不是SubscribeOnDispatch。请参见此处。