根據我的理解Dispatcher.Invoke和Dispatcher.BeginInvoke在UI線程上執行,唯一的區別是Invoke是同步的,BeginInvoke是異步的。我的問題是當我使用此代碼線程問題與Dispatcher.Invoke和Dispatcher.BeginInvoke
EDisc.App.Current.Dispatcher.
Invoke(
DispatcherPriority.Normal, new Action(delegate
{
context = NavigationManager.CurrentPage.DataContext;
}));
返回上下文的值。但是與下面的代碼
EDisc.App.Current.Dispatcher.
BeginInvoke(
DispatcherPriority.Normal, new Action(delegate
{
context = NavigationManager.CurrentPage.DataContext;
}));
上下文爲null,並且我得到InvalidOperation異常說「,因爲不同的線程擁有它。我是從一個WCF服務調用此
調用線程不能訪問此對象,與UseSynchronizationContext執行=假。可有人解釋這種現象?
EDisc.App'的類型是什麼? – JaredPar 2010-12-14 07:35:04
它是應用程序對象的類名。應用程序x:Class =「EDisc.App」 – Rohit 2010-12-14 08:18:42