79536445

Date: 2025-03-26 12:47:14
Score: 1
Natty:
Report link

I have a Blazor Hybrid Maui app that uses websocketclient. When user navigates away from the page, I need to gracefully close the connection. I use OnLocationChanged(). That should work for you as well.

private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
    if (e.IsNavigationIntercepted)
    {
        // Handle the page closing event here
        ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Page Closing", CancellationToken.None);
    }
}
Reasons:
  • Blacklisted phrase (0.5): I need
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Scott Carter