using Microsoft.AspNetCore.Components.Server.Circuits; namespace ZB.MOM.WW.MxGateway.Server.Dashboard; /// /// Per-circuit view of whether the browser is still attached. Registered scoped, so a /// page injecting it sees its own circuit, and also registered as that circuit's /// so Blazor drives it. /// /// /// A closed or backgrounded browser tab leaves its circuit alive, disconnected, for /// /// before Blazor disposes it, and every timer on the page keeps running in that /// window. The Browse page's two-second ReadBulk poll is the costly one — it /// drives the shared dashboard worker — so it skips its tick while /// is false and resumes on reconnect. /// public sealed class DashboardCircuitConnectionTracker : CircuitHandler { private volatile bool _connected = true; /// /// Gets a value indicating whether the circuit's browser connection is up. True /// until Blazor reports the connection down, and also outside a circuit (prerender), /// where no handler callbacks ever arrive. /// public bool IsConnected => _connected; /// public override Task OnConnectionUpAsync(Circuit circuit, CancellationToken cancellationToken) { _connected = true; return Task.CompletedTask; } /// public override Task OnConnectionDownAsync(Circuit circuit, CancellationToken cancellationToken) { _connected = false; return Task.CompletedTask; } }