Search code examples
xamarin.androidmvvm-light

Messenger: How to wait for messages to be processed?


I have an Xamarin.Android Application using MVVMLight messenger.

The application is also using a background service.

Both the application and the service register to a StopApplicationAndServiceMessage message:

Messenger.Default.Register<StopApplicationAndServiceMessage>(...)

They each pass a custom method to se second parameter.

The application menu has an option to quit the application that posts the StopApplicationAndServiceMessage message.

Messenger.Default.Send(new StopApplicationAndServiceMessage(reason));

When processing the message in the application, is there a way to wait for/ensure that the message has been processed by the background service?

Any help appreciated.


Solution

  • The second parameter set in Register method is used to ensure the message received .

    Messenger.Default.Register<StopApplicationAndServiceMessage>(
      this,
      message =>
      {
         // message processed here .
      });