public HLSRequestManager( IMemoryCache memoryCache, IOptions <JT1078Configuration> jT1078ConfigurationAccessor, JT1078HttpSessionManager httpSessionManager, JT1078SessionManager sessionManager, FileSystemWatcher fileSystemWatcher, ILoggerFactory loggerFactory) { this.memoryCache = memoryCache; this.fileSystemWatcher = fileSystemWatcher; HttpSessionManager = httpSessionManager; SessionManager = sessionManager; Configuration = jT1078ConfigurationAccessor.Value; Logger = loggerFactory.CreateLogger <HLSRequestManager>(); Task.Run(() => { while (true) { var expireds = HttpSessionManager.GetAll().Where(m => DateTime.Now.Subtract(m.StartTime).TotalSeconds > 20).ToList(); foreach (var item in expireds) { //移除httpsession HttpSessionManager.TryRemoveBySim(item.Sim); //移除tcpsession SessionManager.RemoveByTerminalPhoneNo(item.Sim); } Thread.Sleep(TimeSpan.FromSeconds(10)); } }); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { await Task.Run(() => { try { foreach (var notice in SessionNoticeService.SessionNoticeBlockingCollection.GetConsumingEnumerable(stoppingToken)) { if (logger.IsEnabled(LogLevel.Information)) { logger.LogInformation($"[Notice]:{notice.SIM}-{notice.ProtocolType}-{notice.SessionType}"); } if (JT1078GatewayConstants.SessionOffline == notice.SessionType) { if (HttpSessionManager != null) { //当1078设备主动断开的情况下,需要关闭所有再观看的连接 HttpSessionManager.TryRemoveBySim(notice.SIM); } } } } catch { } }, stoppingToken); }