🎓 All Courses | 📚 Blazor WASM Syllabus
Stickipedia University
📋 Study this course on TaskLoco

SignalR enables real-time bi-directional communication between a Blazor WASM client and an ASP.NET Core server. Use it for live dashboards, chat, notifications, and collaborative features.

Install the Client Package

dotnet add package Microsoft.AspNetCore.SignalR.Client

Connecting to a Hub

@implements IAsyncDisposable

@code {
    private HubConnection? hubConnection;

    protected override async Task OnInitializedAsync()
    {
        hubConnection = new HubConnectionBuilder()
            .WithUrl(Nav.ToAbsoluteUri("/chathub"))
            .WithAutomaticReconnect()
            .Build();

        hubConnection.On<string, string>("ReceiveMessage", (user, msg) =>
        {
            messages.Add($"{user}: {msg}");
            InvokeAsync(StateHasChanged);
        });

        await hubConnection.StartAsync();
    }

    public async ValueTask DisposeAsync()
    {
        if (hubConnection is not null)
            await hubConnection.DisposeAsync();
    }
}

Key Rules

  • Always use InvokeAsync(StateHasChanged) from SignalR callbacks — they run on background threads
  • Use WithAutomaticReconnect() for resilience
  • Always implement IAsyncDisposable

YouTube • Top 10
Blazor WASM: SignalR Real-Time Features
Tap to Watch ›
📸
Google Images • Top 10
Blazor WASM: SignalR Real-Time Features
Tap to View ›

Reference:

Wikipedia: SignalR

image for linkhttps://en.wikipedia.org/wiki/SignalR

📚 Blazor WASM — Full Course Syllabus
📋 Study this course on TaskLoco

TaskLoco™ — The Sticky Note GOAT