2013-07-19 05:47:55 +02:00
|
|
|
|
using System;
|
2011-10-07 08:36:04 +02:00
|
|
|
|
using System.Diagnostics;
|
2012-02-11 02:43:07 +01:00
|
|
|
|
using System.Threading;
|
2011-10-07 08:36:04 +02:00
|
|
|
|
using NLog;
|
2011-10-23 07:26:43 +02:00
|
|
|
|
using NzbDrone.Common;
|
2011-10-07 08:36:04 +02:00
|
|
|
|
|
2013-03-01 01:50:50 +01:00
|
|
|
|
namespace NzbDrone
|
2011-10-07 08:36:04 +02:00
|
|
|
|
{
|
2013-03-01 01:50:50 +01:00
|
|
|
|
public class PriorityMonitor
|
2011-10-07 08:36:04 +02:00
|
|
|
|
{
|
2013-05-11 01:53:50 +02:00
|
|
|
|
private readonly IProcessProvider _processProvider;
|
2013-03-01 01:50:50 +01:00
|
|
|
|
private readonly Logger _logger;
|
2011-10-07 08:36:04 +02:00
|
|
|
|
|
2012-02-11 02:43:07 +01:00
|
|
|
|
private Timer _processPriorityCheckTimer;
|
2011-10-07 08:36:04 +02:00
|
|
|
|
|
2013-05-11 01:53:50 +02:00
|
|
|
|
public PriorityMonitor(IProcessProvider processProvider, Logger logger)
|
2011-10-07 08:36:04 +02:00
|
|
|
|
{
|
|
|
|
|
_processProvider = processProvider;
|
2013-03-01 01:50:50 +01:00
|
|
|
|
_logger = logger;
|
2011-10-07 08:36:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2012-02-11 02:43:07 +01:00
|
|
|
|
_processPriorityCheckTimer = new Timer(EnsurePriority);
|
|
|
|
|
_processPriorityCheckTimer.Change(TimeSpan.FromSeconds(15), TimeSpan.FromMinutes(30));
|
2011-10-07 08:36:04 +02:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-11 02:43:07 +01:00
|
|
|
|
public virtual void EnsurePriority(object sender)
|
2011-10-07 08:36:04 +02:00
|
|
|
|
{
|
2012-03-02 20:58:31 +01:00
|
|
|
|
try
|
2011-10-07 08:36:04 +02:00
|
|
|
|
{
|
2012-03-02 20:58:31 +01:00
|
|
|
|
var currentProcess = _processProvider.GetCurrentProcess();
|
|
|
|
|
if (currentProcess.Priority != ProcessPriorityClass.Normal)
|
|
|
|
|
{
|
|
|
|
|
_processProvider.SetPriority(currentProcess.Id, ProcessPriorityClass.Normal);
|
|
|
|
|
}
|
2011-10-07 08:36:04 +02:00
|
|
|
|
|
2013-02-19 02:13:42 +01:00
|
|
|
|
var iisProcess = _processProvider.GetProcessById(_processProvider.GetCurrentProcess().Id);
|
2012-03-02 20:58:31 +01:00
|
|
|
|
if (iisProcess != null && iisProcess.Priority != ProcessPriorityClass.Normal &&
|
|
|
|
|
iisProcess.Priority != ProcessPriorityClass.AboveNormal)
|
|
|
|
|
{
|
|
|
|
|
_processProvider.SetPriority(iisProcess.Id, ProcessPriorityClass.Normal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
2011-10-07 08:36:04 +02:00
|
|
|
|
{
|
2013-03-01 01:50:50 +01:00
|
|
|
|
_logger.WarnException("Unable to verify priority", e);
|
2011-10-07 08:36:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|