Unsubscribing from valuechanged doesnt work

yussuf

I have this code to subscribe

    reference.Child("power").OrderByValue().LimitToLast(50).ValueChanged += HandleValueChanged;

then

 void HandleValueChanged(object sender, ValueChangedEventArgs args)
    {
        if (args.DatabaseError != null)
        {
            Debug.Log(args.DatabaseError.Message);
            return;
        }
        looperr = 49;
        snapo = args.Snapshot;
        showplayername.text = playername;
        showpower.text = calco.totalpower.ToString("###");
        looper();
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference.Child("power");
        reference.OrderByValue().LimitToLast(50).ValueChanged -= HandleValueChanged;
    }

however it still send changes after unsubscribing i tried moving the unsubscribe method and delay it but still doesn't work

Frank van Puffelen

I think the subscriptions may be instance based. If that is the case, you'll need to keep the query in a variable, and subscribe/unsubscribe on the same variable.

So something like:

var query = reference.OrderByValue().LimitToLast(50)

...

query.ValueChanged += HandleValueChanged

...

query.ValueChanged -= HandleValueChanged

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does event unsubscribing work ("not leak") if using a lambda returned from a method?

Setting classpath from bat file doesnt work

OBJC @selector doesnt work from another implementation

Extract numbers from string doesnt work! c

onitemclick listener doesnt work from Dialog

Booting from a pendrive(USB) doesnt work !

Loading file from Directory to UIIMAGE doesnt work

phalcon forward() doesnt work from helper function

Loading anchor from url async doesnt work

jQuery take value from input doesnt work

Reactivity doesnt work from within Vue Component

Performsegue from another viewcontroller doesnt' work

Unsubscribing from Observables inside services?

Unsubscribing from Firebase Realtime Database

Unsubscribing from a ReplaySubject returned asObservable();

Immediately unsubscribing from RxJS Observable

Unsubscribing from events on page change

Bookmarklets doesnt work when run from bookmark, but works from console

Maya Python Script works from console, doesnt work from file

Unsubscribing from RxJava2/RxAndroid PublishSubject

Unsubscribing Multiple Subscription from Different Functions

Unsubscribing from the event in delegate vs function

Unsubscribing from queryparammap - has this become necessary?

Unsubscribing from an rx.Single in RxJava

Issue when unsubscribing from onSnapshot listener?

selection condition in php doesnt work when comparing data from database

dynamically creating bootstrap dropdown from jQuery AJAX doesnt work

Retrieving Data from firebase database (Working in console but doesnt work in code)

Left click doesnt work after upgrade to 20.04 from bionic