Search code examples
c#wpfmvvmprismeventaggregator

How to control the execute sequence of event handler with EventAggregator in Prism


I'm using Prism EventAggregator in my app. In my scenario, it's a download module, when download completion, publish the event. Four ViewModels subscribe this event and have their own event handler, some for writing log file, some for updating user interface.

  • How to control these event handlers execution sequence?
  • Are there executing in parallel?

Solution

  • By default, they execute on the same thread that the event was published. If you are specifying a thread (UI / Worker), then they may execute in parallel.

    Invocation of the event handlers is generally the order in which they subscribed, but I wouldn't depend on this behavior.

    Why do you care about the order? Is it because you have many phases of initialization? Send out a seperate message for each phase.