【发布时间】:2014-11-03 10:01:52
【问题描述】:
在我的 ViewModel 构造函数中的 Windows Phone 应用程序中,我像这样注册了一个信使:
Messenger.Default.Register<MyType>
(
this,
(action) => ReceiveMessage(action)
);
然后在 ReceiveMessage 中我尝试输入一些代码,然后它崩溃了
"The application called an interface that was marshalled for a different thread."
private void ReceiveMessage(MyType action)
{
this.MyCollection.Clear();
foreach (Student st in Students)
{
this.MyCollection.Add(st);
}
}
我试过这样做,结果是一样的:
Application.Current.Resources.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => this.MyCollection.Clear());
【问题讨论】:
标签: c# multithreading mvvm notifications messages