I am using MVVM Light to send a message between two ViewModels. In the receiving VM, i am trying the following
Messenger.Default.Register<NotificationMessage>(this, async (msg) => {
await HandleMessage(msg);
});
private async Task HandleMessage(NoficationMessage message)
{
... code using await
}
The first time the message gets sent (via a button click), the async method runs. The next time the message gets sent nothing happens - the method does not get called (checked via a breakpoint).
Is async allowed on the Register method in this way?
What would be a workaround?
I believe for async events, you need void.
Try the following
Messenger.Default.Register<NotificationMessage>(this, HandleMessage);
private async void HandleMessage(NotificationMessagemessage)
{
... code using await
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.