Prism Unsubscribe from token does not work

I sign and unsubscribe prisms using the code below in ClassA. The problem I encountered is after , I unsubscribe, and another completely different class, such as ClassB, with different handler registers for the same event, the ClassA handler is still called. Why is this?

I tried both to cancel the subscription using the token and the delegate of the method used during registration, and 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); 
+7
source share
2 answers

I don't think Unsubscribe might work there since you used an anonymous method to call Subscribe. Try moving the code to subscribe in a separate method and subscribe / unsubscribe from it / from it.

+2
source

I am not sure if there is a code for subscription here.

But we can subscribe and unsubscribe from the event as follows:

 evenaggregator.GetEvent<EventName>().Subscribe(eventhandler); 

and

 evenaggregator.GetEvent<EventName>().Unsubscribe(eventhandler); 

This works for me.

0
source

All Articles