Reputation: 331
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?
Upvotes: 5
Views: 1853
Reputation: 4278
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
}
Upvotes: 5