0
我试图从数据库检索数据使用实体框架5.0代码快速和反应性扩展(Rx)。我正在为此编写以下代码。'System.Reactive.Concurrency.Scheduler.NewThread'已过时
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.
请建议我我如何使用无扩展(Rx)的正确的EF5.0在我的WPF应用程序中快速编码或以任何连击方式异步调用数据库。
您是否尝试根据提供给您的消息更改您的代码? – 2013-02-16 11:17:14
ya。现在警告消失了。但异常仍然存在。 – 2013-02-16 11:36:02
请参阅此问题的答案 - http://stackoverflow.com/questions/7579237/whats-the-difference-between-subscribeon-and-lookeon。看起来'SubscribeOnDispatcher'不一定将您对'ItemCollection.Add'的调用封送回UI线程。 – 2013-02-16 13:40:42