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