Back to results for “SignalR”
.NET MAUI › Networking & APIs

How do you handle real-time updates (WebSockets/SignalR) in a MAUI app?

Advanced

Answer

Use the SignalR client (Microsoft.AspNetCore.SignalR.Client) or ClientWebSocket for push updates. Start the connection in a service, subscribe to hub events, and marshal updates to the UI thread. Manage the connection lifecycle with app state—reconnect on resume, stop or background appropriately on sleep.
var hub = new HubConnectionBuilder()
    .WithUrl("https://api.example.com/chat").WithAutomaticReconnect().Build();
hub.On<string>("Receive", msg =>
    MainThread.BeginInvokeOnMainThread(() => Messages.Add(msg)));
await hub.StartAsync();
Real-world example A chat app receives messages instantly over SignalR and reconnects automatically after transient drops.

Common follow-ups: How do you tie connections to app lifecycle? | What is WithAutomaticReconnect?