I am subscribing and unsubscribing to prism events using the code below in ClassA. The problem I am having is after I unsubscribe, and another completely different class, say ClassB, with a different handler registers for the same event, ClassA handler is still invoked. Why is this?
I have tried both unsubscribing using a token as well as the method delegate used when registering, both to no avail.
SubscriptionToken _subscriptionToken;
//register subscription + handler
var pevent = GetEventAggregator().GetEvent<PriceSubscriptionEvent>();
_subscriptionToken = pevent.Subscribe(r =>
{
DataHandler(r);
return;
}, ThreadOption.BackgroundThread, false, null);
//Unsubscribe
var pevent = GetEventAggregator().GetEvent<PriceSubscriptionEvent>();
pevent.Unsubscribe(_subscriptionToken);
I don't think the Unsubscribe can work there since you used an anonymous method on your Subscribe call. Try moving the code for subscribe in a separate method and the subscribe / unsubscribe to / from it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With