我正在尝试使用Entity-Framework 5.0 Code fast and Reactive Extensions(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.'
在RunTime,我得到一个异常:
The calling thread cannot access this object because a different thread owns it.
请建议我如何在我的WPF应用程序中快速使用EF5.0代码中的Reactive Extensions(Rx)或任何以异步方式调用数据库的方式。