I am using Prism in my WPF application.
I have subscribed to an Event.
_iEventAggregator.GetEvent<MyEvent>().Unsubscribe(AddSubscription);
AddSubscription = _iEventAggregator.GetEvent<MyEvent>().Subscribe((i) =>
{
Added(ViewModel, i);
});
Publish the event in some other class. It is working fine in the Debug mode. But While switching to the release mode it is not working fine. i.e The subscriber method not gets hit in the source and the part is not executed.
How to check this issue, Is there any way to know my subscription is successful and overcome this issue.
You have to make sure that the subscriber is alive (that is, constructed and not garbage collected) when the event is published.
The subscription alone will not keep the subscriber alive unless you subscribe with keepSubscriberReferenceAlive: true
.
Edit:
If you use the EventAggregator
to keep your subscriber alive, be sure to dispose of the subscription when it's no longer needed, otherwise you introduce a memory leak.