mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 19:37:55 +02:00
update use of timers
This commit is contained in:
parent
0361b8b0e8
commit
00de5b1ca7
3 changed files with 13 additions and 23 deletions
|
@ -36,7 +36,7 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||||
private readonly IMediaSourceManager _mediaSourceManager;
|
private readonly IMediaSourceManager _mediaSourceManager;
|
||||||
|
|
||||||
private readonly List<string> _nonRendererUrls = new List<string>();
|
private readonly List<string> _nonRendererUrls = new List<string>();
|
||||||
private Timer _clearNonRenderersTimer;
|
private DateTime _lastRendererClear;
|
||||||
|
|
||||||
public PlayToManager(ILogger logger, ISessionManager sessionManager, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost, IImageProcessor imageProcessor, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, IServerConfigurationManager config, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager)
|
public PlayToManager(ILogger logger, ISessionManager sessionManager, ILibraryManager libraryManager, IUserManager userManager, IDlnaManager dlnaManager, IServerApplicationHost appHost, IImageProcessor imageProcessor, IDeviceDiscovery deviceDiscovery, IHttpClient httpClient, IServerConfigurationManager config, IUserDataManager userDataManager, ILocalizationManager localization, IMediaSourceManager mediaSourceManager)
|
||||||
{
|
{
|
||||||
|
@ -57,19 +57,9 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
_clearNonRenderersTimer = new Timer(OnClearUrlTimerCallback, null, TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(10));
|
|
||||||
|
|
||||||
_deviceDiscovery.DeviceDiscovered += _deviceDiscovery_DeviceDiscovered;
|
_deviceDiscovery.DeviceDiscovered += _deviceDiscovery_DeviceDiscovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClearUrlTimerCallback(object state)
|
|
||||||
{
|
|
||||||
lock (_nonRendererUrls)
|
|
||||||
{
|
|
||||||
_nonRendererUrls.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async void _deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e)
|
async void _deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e)
|
||||||
{
|
{
|
||||||
string usn;
|
string usn;
|
||||||
|
@ -99,6 +89,12 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||||
|
|
||||||
lock (_nonRendererUrls)
|
lock (_nonRendererUrls)
|
||||||
{
|
{
|
||||||
|
if ((DateTime.UtcNow - _lastRendererClear).TotalMinutes >= 10)
|
||||||
|
{
|
||||||
|
_nonRendererUrls.Clear();
|
||||||
|
_lastRendererClear = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
if (_nonRendererUrls.Contains(location, StringComparer.OrdinalIgnoreCase))
|
if (_nonRendererUrls.Contains(location, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
@ -181,12 +177,6 @@ namespace MediaBrowser.Dlna.PlayTo
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_deviceDiscovery.DeviceDiscovered -= _deviceDiscovery_DeviceDiscovered;
|
_deviceDiscovery.DeviceDiscovered -= _deviceDiscovery_DeviceDiscovered;
|
||||||
|
|
||||||
if (_clearNonRenderersTimer != null)
|
|
||||||
{
|
|
||||||
_clearNonRenderersTimer.Dispose();
|
|
||||||
_clearNonRenderersTimer = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.IO;
|
|
||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Notifications;
|
using MediaBrowser.Controller.Notifications;
|
||||||
|
@ -17,12 +16,13 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using CommonIO;
|
using CommonIO;
|
||||||
|
using MediaBrowser.Common.Threading;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Implementations.News
|
namespace MediaBrowser.Server.Implementations.News
|
||||||
{
|
{
|
||||||
public class NewsEntryPoint : IServerEntryPoint
|
public class NewsEntryPoint : IServerEntryPoint
|
||||||
{
|
{
|
||||||
private Timer _timer;
|
private PeriodicTimer _timer;
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
|
@ -47,7 +47,7 @@ namespace MediaBrowser.Server.Implementations.News
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
_timer = new Timer(OnTimerFired, null, TimeSpan.FromMilliseconds(500), _frequency);
|
_timer = new PeriodicTimer(OnTimerFired, null, TimeSpan.FromMilliseconds(500), _frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -4,7 +4,7 @@ using MediaBrowser.Controller.Session;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using MediaBrowser.Common.Threading;
|
||||||
|
|
||||||
namespace MediaBrowser.Server.Startup.Common.EntryPoints
|
namespace MediaBrowser.Server.Startup.Common.EntryPoints
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ namespace MediaBrowser.Server.Startup.Common.EntryPoints
|
||||||
{
|
{
|
||||||
private readonly ISessionManager _sessionManager;
|
private readonly ISessionManager _sessionManager;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private Timer _timer;
|
private PeriodicTimer _timer;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
|
||||||
public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost)
|
public KeepServerAwake(ISessionManager sessionManager, ILogger logger, IServerApplicationHost appHost)
|
||||||
|
@ -24,7 +24,7 @@ namespace MediaBrowser.Server.Startup.Common.EntryPoints
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
_timer = new Timer(obj =>
|
_timer = new PeriodicTimer(obj =>
|
||||||
{
|
{
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
|
if (_sessionManager.Sessions.Any(i => (now - i.LastActivityDate).TotalMinutes < 15))
|
||||||
|
|
Loading…
Reference in a new issue