Alan Rutter
Alan Rutter

Reputation: 331

MVVM Light Messenger Receive Method

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

Answers (1)

SILENT
SILENT

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

Related Questions