Search code examples
multithreadingcaliburn.microeventaggregatorbackground-thread

Caliburn Micro 2 EventAggregator PublishOnBackgroundThread


Can anyone explain any reason why and when should I use PublishOnBackgroundThread instead of PublishOnUIThread.

I cannot find any use cases for usage PublishOnBackgroundThread and I am not sure what method should I use?


Solution

  • It really depends on the type of the message you're publishing.

    If you're using the EventAggregator to surface a message from a low laying service back the UI then PublishOnUIThread makes the most sense since you'll be updating the UI when handling the message. The same applies when you're using it to communicate between view models.

    Conversely sometimes it get used for view models to publish events that an underlying service is listening to (rather than the view model depending on that service).

    That service may perform some expensive work which makes sense to happen on a background thread. Personally I'd have gone in the background service to push that work onto a background thread but different people want different options.

    Ultimately the method was included for completeness.