EventAggregator and Application.Deactivated event

Topics: Prism v2 - WPF 4
Jul 19, 2011 at 3:12 PM

I'm having an interesing problem with CAL and the event aggregator.  I am attempting to publish an event when the app is deactivated or activated (application.activated and application.deactivated).  Some of my modules have popup boxes that a I want to hide when the application loses focus.

this is a small code sample below


    protected override void OnStartup(StartupEventArgs e)

        Deactivated += (s, a) => eventAggregator.GetEvent<AppDeactivatedEvent>().Publish(EmptyPayload.Empty);
        Deactivated += (s, a) => Console.WriteLine("Deactivated - in app.xaml");
        Activated += (s, a) => eventAggregator.GetEvent<AppActivatedEvent>().Publish(EmptyPayload.Empty);





    public void AppDeactivated(EmptyPayload empty)
        Console.WriteLine("App Deactivated - Module");

What happens is that when the app loses focus I get the following in the console
Deactivated - in app.xaml
When the App regains focus I get the below
App Deactivated - Module

Any ideas on why the event aggregator would wait until the app regains focus for the event to fire. 




Jul 19, 2011 at 5:12 PM


You could try changing the subscription in your module to subscribe from a background thread instead of from the UI thread. That might be the reason why this is happening.

If that doesn't work, it would be helpful if you could provide us with a repro sample portraying this behavior, so that we can help you identify the cause of this problem.

I hope you find this helpful.

Guido Leandro Maliandi

Jul 21, 2011 at 9:13 PM

Turns out I had a typo. 


wrong event, oops, thanks though