5
votes

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?

1

1 Answers

4
votes

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
}