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