Light receiving method MVVM Light Messenger

I am using MVVM Light to send a message between two ViewModels. In the host virtual machine, I am trying to do the following

Messenger.Default.Register<NotificationMessage>(this, async (msg) => {
    await HandleMessage(msg);
});

private async Task HandleMessage(NoficationMessage message)
{
    ... code using await
}

The first time a message is sent (by pressing a button), the asynchronous method is executed. The next time the message is sent, nothing happens - the method is not called (it is checked through a breakpoint).

Asynchronously valid for the Register method this way?

What will be the workaround?

+4
source share
1 answer

I believe that for asynchronous events you need an empty one.

Try to execute

Messenger.Default.Register<NotificationMessage>(this, HandleMessage);
private async void HandleMessage(NotificationMessagemessage)
{
    ... code using await
}
+3
source

Source: https://habr.com/ru/post/1614674/


All Articles