4

In my Composite WPF application I have an event that is published when the user double-clicks on a control. Modules subscribe to the event and perform an action when necessary.

This event seems to stop working at random. Sometimes when I run the application I can trigger the event with no problems, other times I can only trigger it a few times before the modules stop receiving the event.

When I look in the debugger the CAL EventAggregator still has the event, but the event has no subscriptions. How can EventAggregator be losing subscriptions?

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243

1 Answers1

4

Turns out it was the garbage collector removing the subscriptions. I'll have to read up on the internals, but when I replaced

this.mEventAggregator.GetEvent<SomeEvent>().Subscribe(SomeFunction);

with

this.mEventAggregator.GetEvent<SomeEvent>().Subscribe(
    SomeFunction, ThreadOption.UIThread, true);

it started working. The UI thread parameters wasn't my problem, but for others it may be important to ensure you're handling the event on the right thread too.

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243
  • 1
    The EventAggregator uses weak references (http://msdn.microsoft.com/en-us/library/ms404247.aspx) unless you explicitly tell it not to. – sourcenouveau Jul 15 '09 at 19:07