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

Blazor .NET 8 : subscribe to async event

$
0
0

I'm trying to get my child components to subscribe to a notification event by invoking it inside my service. How do I subscribe to it? I'm getting an error stating I cannot implicitly convert type System.Threading.Tasks.Task to System.Func<System.Threading.Tasks.Task>.

Here's my service implementation:

public event Func<Task> Notify;

Then I have a child method to call inside my service:

public async Task Subscribe(string value){    ...    await Notify!.Invoke();}

Then in my child component, I'm trying to subscribe like so:

private async Task OnNotify(){    await InvokeAsync(() =>{        ...        StateHasChanged();    });        }

Inside my OnInitializedAsync() method is where I'm trying to subscribe but I get the above error:

protected override Task OnInitializedAsync(){    Notifier.Notify += OnNotify();    return base.OnInitializedAsync();}

How do I subscribe to an asynchronous event when it returns Func<Task>?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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