EventAggregator

Topics: Prism v4 - WPF 4
Apr 26, 2012 at 10:32 AM

Hi ,

I am using EventAggregator , where i am choosing to go for weakreference while publishing the events . When doing so few of the times i could observe subsciber method is not getting invoked . When i tried the same sample with strong reference by setting true to the third parameter while publishing the event , everything seems to be working fine.

Are there any problems with EventAggregator ?

 

Thanks

 

Developer
Apr 26, 2012 at 6:35 PM

Hi,

In my opinion this problem could be related to the use of Weak Reference to the subscriber instance, as the garbage collector could be disposing the subscriber instance in case there are no strong references to it. Therefore you should ensure that references to those instances are maintained alive to avoid disposing the corresponding subscriptions.

For example, as mentioned in the Prism documentation:

Module instances lifetime is short-lived by default. After the Initialize method is called during the loading process,the reference to the module instance is released. If you do not establish a strong reference chain to the module instance, it will be garbage collected. And this behavior may be problematic to debug if you subscribe to events that hold a weak reference to your module, because your module just "disappears" when the garbage collector runs.

Based on this, please check that your subscription is still present by the time you publish the event.

Additionally, you could find more information about this and the use of Weak References in the following MSDN article:

If you still can't solve this problem, it would be helpful if you could provide us with more information about your scenario or if you could isolate this behavior in a repro sample application and upload it to SkyDrive or any other storage site you'd like to, and post the link here.

Regards,

Agustin Adami
http://blogs.southworks.net/aadami

May 1, 2012 at 6:18 AM

Hi ,

Thanks for your reply . Its a very simple WPF prism application which i have created . I will share the project to skyDrive and update the link.

 

Thanks.