public async Task OnAuthorizedExpiresInAsync(long seconds) { if (_authPingService == null) { _authPingService = _serviceProvider.GetRequiredService <IAuthStatusService>(); } // Set this timer to trigger after we expire so that it auto triggers a login if (_timerExpiration != null) { _timerExpiration.Dispose(); } _timerExpiration = new Timer(async _ => { await _authPingService.CheckAsync(); }, null, (seconds + 5) * 1000, seconds * 1000000); }
public KeepAliveTimerService(IServiceProvider serviceProvider) { // TODO. Blazor is crashing when I inject IAuthStatusService here. // Works just fine when I request it later using GetRequiredService _serviceProvider = serviceProvider; KeepAlive = false; _timerKeepAlive = new Timer(async _ => { // start a 5 second keep alive timer // This is really here for when I have api calls going to other services // Those calls will not slide out the host, but this will call the host for us. if (KeepAlive) { KeepAlive = false; if (_authPingService == null) { _authPingService = _serviceProvider.GetRequiredService <IAuthStatusService>(); } await _authPingService.CheckAsync(); } }, null, (5) * 1000, (5) * 1000); }