1
我有一個問題,我使用Application.Current
名稱空間的Dispatcher
類運行我的部分代碼。然後我想使用由Dispatcher.Invoke()
返回的任務的ContinueWith
方法構建一個後續操作。Application.Current.Dispatcher.Invoke()從一個動作
在這種特殊情況下,後續操作需要在UI線程中運行,因此需要再次將其包裝在Dispatcher.Invoke
中。這是我得到它的工作:
Action doSomeMoreStuff =() => { this.MoreStuff; }
Application.Current.Dispatcher.Invoke(() => this.DoStuff).ContinueWith(x => Application.Current.Dispatcher.Invoke(this.DoSomeMoreStuff));
我想保留它通用不過了,有可能是在那裏我不想跟進代碼從UI線程中運行的情況。於是,我就封裝跟進代碼本身:
Action doSomeMoreStuff =() => { Application.Current.Dispatcher.Invoke(this.MoreStuff); }
Application.Current.Dispatcher.Invoke(() => this.DoStuff).ContinueWith(x => this.DoSomeMoreStuff);
所以,據我理解這個問題,我簡單地切換的Application.Current.Dispatcher.Invoke()
調用的位置。但是,第二種方法不起作用,代碼不會被調用,我不知道爲什麼。
我不在這裏?
使用異步/等待。 –
你可以更具體一點,即發表一個例子嗎? – Slicky
[這裏](http://tinyurl.com/mzlkyl7)。 –