Merge pull request #561 from PepperDash/feature/genericqueue-upgrades

#560 Adds constructors with priority and fixed debug statments to use…
This commit is contained in:
Neil Dorin
2021-01-25 11:18:46 -07:00
committed by GitHub

View File

@@ -15,23 +15,36 @@ namespace PepperDash_Essentials_Core.Queues
protected readonly Thread _worker; protected readonly Thread _worker;
protected readonly CEvent _waitHandle = new CEvent(); protected readonly CEvent _waitHandle = new CEvent();
private readonly bool _delayEnabled; private bool _delayEnabled;
private readonly int _delayTime; private int _delayTime;
/// <summary> /// <summary>
/// If the instance has been disposed. /// If the instance has been disposed.
/// </summary> /// </summary>
public bool Disposed { get; private set; } public bool Disposed { get; private set; }
/// <summary>
/// Constructor with no thread priority
/// </summary>
/// <param name="key"></param>
public GenericQueue(string key)
: this(key, Thread.eThreadPriority.NotSet)
{
}
/// <summary> /// <summary>
/// Constructor for generic queue with no pacing /// Constructor for generic queue with no pacing
/// </summary> /// </summary>
/// <param name="key">Key</param> /// <param name="key">Key</param>
public GenericQueue(string key) public GenericQueue(string key, Thread.eThreadPriority priority)
{ {
_key = key; _key = key;
_queue = new CrestronQueue<IQueueMessage>(); _queue = new CrestronQueue<IQueueMessage>();
_worker = new Thread(ProcessQueue, null, Thread.eThreadStartOptions.Running); _worker = new Thread(ProcessQueue, null, Thread.eThreadStartOptions.Running)
{
Priority = priority
};
CrestronEnvironment.ProgramStatusEventHandler += programEvent => CrestronEnvironment.ProgramStatusEventHandler += programEvent =>
{ {
@@ -49,11 +62,28 @@ namespace PepperDash_Essentials_Core.Queues
/// <param name="pacing">Pacing in ms between actions</param> /// <param name="pacing">Pacing in ms between actions</param>
public GenericQueue(string key, int pacing) public GenericQueue(string key, int pacing)
: this(key) : this(key)
{
SetDelayValues(pacing);
}
/// <summary>
/// Constructor with pacing and priority
/// </summary>
/// <param name="key"></param>
/// <param name="pacing"></param>
/// <param name="priority"></param>
public GenericQueue(string key, int pacing, Thread.eThreadPriority priority)
: this(key, priority)
{
SetDelayValues(pacing);
}
private void SetDelayValues(int pacing)
{ {
_delayEnabled = pacing > 0; _delayEnabled = pacing > 0;
_delayTime = pacing; _delayTime = pacing;
} }
/// <summary> /// <summary>
/// Thread callback /// Thread callback
/// </summary> /// </summary>
@@ -83,7 +113,7 @@ namespace PepperDash_Essentials_Core.Queues
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.ConsoleWithLog(0, this, "Caught an exception in the Queue {0}\r{1}\r{2}", ex.Message, ex.InnerException, ex.StackTrace); Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Caught an exception in the Queue {0}\r{1}\r{2}", ex.Message, ex.InnerException, ex.StackTrace);
} }
} }
else _waitHandle.Wait(); else _waitHandle.Wait();