Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Callbacks still active after component disposed

$
0
0

I am using Carl Franklin's (youtu.be/sem1s92skAU?t=665) pattern for app state and event callbacks instead of events that require dispose. Here's the basic code:

In the page component:

    AppState.RegisterCallback(EventCallback.Factory.Create<StatePropertyChangedArgs>(this, HandlePropertyChanged));

And in the appstate class:

public void RegisterCallback(EventCallback<StatePropertyChangedArgs> callback){    if (!Callbacks.Contains(callback))    {        Callbacks.Add(callback);    }}private void NotifyPropertyChanged(StatePropertyChangedArgs args){            foreach (var callback in Callbacks)    {        try        {            callback.InvokeAsync(args);        }        catch { }    }}

This works fine, except that the disposed page component, continues to call it's registered callback - AFTER it's been disposed (verified by implementing IDisposable).

I thought that it would throw an exception (hence the catch) once it was disposed.

Am I missing something here? Did I misunderstand the pattern he explained? I thought that this was a "better pattern" to avoid having to add/remove events, but it doesn't seem to be self-removing.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>