【发布时间】:2014-01-25 02:56:13
【问题描述】:
我正在使用 MvvmLight 并使用 MessengerInstance.Send(...) 方法实现了我的一些 ViewModel 之间的通信。效果很好!
不过,最近,我已经从使用同步方法转移到异步方法来检索数据,看起来这会破坏消息传递(可能是因为它在不同的线程上执行)。例如:
public ICommand SomeCommand { get { return new RelayCommand(DoSomething); } }
private async void DoSomething(object obj)
{
//Used to be SomeWcfService.DoSomething(); with some logic afterward
await SomeWcfService.DoSomethingAsync().ContinueWith(task => { //Some logic after method completes });
MessengerInstance.Send(SomeDataToSend, MessageIdentifer.DoSomething);
}
【问题讨论】:
标签: c# wpf mvvm task-parallel-library mvvm-light