1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone/PriorityMonitor.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2013-07-19 06:47:55 +03:00
using System;
2011-10-07 09:36:04 +03:00
using System.Diagnostics;
using System.Threading;
2011-10-07 09:36:04 +03:00
using NLog;
using NzbDrone.Common;
2011-10-07 09:36:04 +03:00
2013-03-01 03:50:50 +03:00
namespace NzbDrone
2011-10-07 09:36:04 +03:00
{
2013-03-01 03:50:50 +03:00
public class PriorityMonitor
2011-10-07 09:36:04 +03:00
{
2013-05-11 02:53:50 +03:00
private readonly IProcessProvider _processProvider;
2013-03-01 03:50:50 +03:00
private readonly Logger _logger;
2011-10-07 09:36:04 +03:00
private Timer _processPriorityCheckTimer;
2011-10-07 09:36:04 +03:00
2013-05-11 02:53:50 +03:00
public PriorityMonitor(IProcessProvider processProvider, Logger logger)
2011-10-07 09:36:04 +03:00
{
_processProvider = processProvider;
2013-03-01 03:50:50 +03:00
_logger = logger;
2011-10-07 09:36:04 +03:00
}
public void Start()
{
_processPriorityCheckTimer = new Timer(EnsurePriority);
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
2011-10-07 09:36:04 +03:00
}
public virtual void EnsurePriority(object sender)
2011-10-07 09:36:04 +03:00
{
try
2011-10-07 09:36:04 +03:00
{
if (_processProvider.GetCurrentProcessPriority() != ProcessPriorityClass.Normal)
{
_processProvider.SetPriority(_processProvider.GetCurrentProcess().Id, ProcessPriorityClass.Normal);
}
}
catch (Exception e)
2011-10-07 09:36:04 +03:00
{
2013-03-01 03:50:50 +03:00
_logger.WarnException("Unable to verify priority", e);
2011-10-07 09:36:04 +03:00
}
}
}
}