Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 681
Alan Rutter Avatar asked Nov 06 '15 02:11

Alan Rutter


People also ask

What is Mvvm messaging?

MVVM Light Messenger is a class that allows exchange messages between objects. Messenger class is mainly used for sending messages between viewmodels. Messenger class decreases coupling between viewmodels. Every viewmodel can communicate with another viewmodel without any association between them.

What is the difference between the Mvvm Cross and MVVM Light?

The difference is that MVVM Light wraps a lot of this in a view-model locator—a static class used to register services and get view models. MvvmCross has some setup code provided by the framework, and inside this setup code you initialize the content of the IoC container.

What is MVVM Light?

MVVM is a pattern on how to structure your UI and data and business logic. MVVM light is a lightweight framework that supports you in implementing the pattern.

What is MVVM Light Toolkit?

The MVVM Light Toolkit is a set of components helping people to get started in the Model-View-ViewModel pattern in Silverlight, WPF, Windows Phone, Windows 10 UWP, Xamarin. Android, Xamarin. iOS, Xamarin. Forms. It is a light and pragmatic framework that allows you to pick which components you want to use.


1 Answers

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
}
like image 50
SILENT Avatar answered Sep 28 '22 08:09

SILENT