1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 01:57:21 +00:00
Lidarr/NzbDrone/PriorityMonitor.cs
2013-02-28 23:05:24 -08:00

53 lines
No EOL
1.6 KiB
C#

using System.Linq;
using System;
using System.Diagnostics;
using System.Threading;
using NLog;
using NzbDrone.Common;
namespace NzbDrone
{
public class PriorityMonitor
{
private readonly ProcessProvider _processProvider;
private readonly Logger _logger;
private Timer _processPriorityCheckTimer;
public PriorityMonitor(ProcessProvider processProvider, Logger logger)
{
_processProvider = processProvider;
_logger = logger;
}
public void Start()
{
_processPriorityCheckTimer = new Timer(EnsurePriority);
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
}
public virtual void EnsurePriority(object sender)
{
try
{
var currentProcess = _processProvider.GetCurrentProcess();
if (currentProcess.Priority != ProcessPriorityClass.Normal)
{
_processProvider.SetPriority(currentProcess.Id, ProcessPriorityClass.Normal);
}
var iisProcess = _processProvider.GetProcessById(_processProvider.GetCurrentProcess().Id);
if (iisProcess != null && iisProcess.Priority != ProcessPriorityClass.Normal &&
iisProcess.Priority != ProcessPriorityClass.AboveNormal)
{
_processProvider.SetPriority(iisProcess.Id, ProcessPriorityClass.Normal);
}
}
catch (Exception e)
{
_logger.WarnException("Unable to verify priority", e);
}
}
}
}