Open Closed

Background Task to Page comms with / without sockets / signal r #1241


User avatar
0
nowayja created

ABP 4.3.0 Blazor

In other Blazor server projects I have used the following technique to communicate between background servces and the pages

https://dzone.com/articles/blazor-how-tos-status-from-a-background-task

An alternate to this would be sockets but I would prefer to use

@code{
    protected override void OnInitialized()
    {
        State.OnChangeAsync += Refresh;
    }
    private async Task Refresh()
    {
        await InvokeAsync(StateHasChanged);
    }
    public void Dispose()
    {
        State.OnChangeAsync -= Refresh;
    }
}

Do you know iif this approach will work with Blazor WASM or should I fallback to traditional SignalR sockets

Many thanks in advance

J


3 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    @nowayja for my late response, @mladen will that work?

  • User Avatar
    0
    mladen.macanovic created

    The way of how you re-render component with StateHasChanged is the same with both Blazor WASM and Blazor Server projects. There is no diference there. But, since you mention SignalR, that is only possible with Blazor Server by default.

    If you want to have SIgnalR for Blazor WASM you will need to implement it in your project. Here is one way on how to implement it https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr-blazor?view=aspnetcore-5.0&tabs=visual-studio&pivots=webassembly

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11