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?
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.
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.
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.
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With