From 955d68b3f3632835c6249ecb107db887fdee0cc1 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 30 Mar 2021 15:56:05 -0600 Subject: [PATCH 1/3] #671 switches to private Dispose() on program stop --- .../PepperDashEssentialsBase/Queues/GenericQueue.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index 693c39e5..36f69e0f 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -155,7 +155,7 @@ namespace PepperDash.Essentials.Core.Queues if (programEvent != eProgramStatusEventType.Stopping) return; - Dispose(); + Dispose(true); }; } @@ -407,7 +407,7 @@ namespace PepperDash_Essentials_Core.Queues if (programEvent != eProgramStatusEventType.Stopping) return; - Dispose(); + Dispose(true); }; } From 2feec6205285d82a961eb9c64ec908b4255cd8d5 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Wed, 31 Mar 2021 16:35:33 -0600 Subject: [PATCH 2/3] Removes explicit call to dispose when program stops. Clears queue in dispose --- .../Queues/GenericQueue.cs | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index 36f69e0f..f2e8000d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -150,13 +150,13 @@ namespace PepperDash.Essentials.Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - CrestronEnvironment.ProgramStatusEventHandler += programEvent => - { - if (programEvent != eProgramStatusEventType.Stopping) - return; + //CrestronEnvironment.ProgramStatusEventHandler += programEvent => + //{ + // if (programEvent != eProgramStatusEventType.Stopping) + // return; - Dispose(true); - }; + // Dispose(true); + //}; } /// @@ -231,6 +231,8 @@ namespace PepperDash.Essentials.Core.Queues if (disposing) { + Debug.Console(2, this, "Disposing..."); + _queue.Clear(); Enqueue(null); _worker.Join(); _waitHandle.Close(); @@ -402,13 +404,13 @@ namespace PepperDash_Essentials_Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - CrestronEnvironment.ProgramStatusEventHandler += programEvent => - { - if (programEvent != eProgramStatusEventType.Stopping) - return; + //CrestronEnvironment.ProgramStatusEventHandler += programEvent => + //{ + // if (programEvent != eProgramStatusEventType.Stopping) + // return; - Dispose(true); - }; + // Dispose(true); + //}; } /// @@ -477,6 +479,8 @@ namespace PepperDash_Essentials_Core.Queues if (disposing) { + Debug.Console(2, this, "Disposing..."); + _queue.Clear(); Enqueue(null); _worker.Join(); _waitHandle.Close(); From 200080247a4e23b42cacc28def902752ca48572f Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 6 Apr 2021 10:38:39 -0600 Subject: [PATCH 3/3] closes #671 and changes to aborting thread in Dispose instead of attempting to join --- .../Queues/GenericQueue.cs | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs index f2e8000d..a5def83d 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Queues/GenericQueue.cs @@ -14,7 +14,7 @@ namespace PepperDash.Essentials.Core.Queues protected readonly CrestronQueue _queue; protected readonly Thread _worker; protected readonly CEvent _waitHandle = new CEvent(); - + private bool _delayEnabled; private int _delayTime; @@ -150,15 +150,15 @@ namespace PepperDash.Essentials.Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - //CrestronEnvironment.ProgramStatusEventHandler += programEvent => - //{ - // if (programEvent != eProgramStatusEventType.Stopping) - // return; + CrestronEnvironment.ProgramStatusEventHandler += programEvent => + { + if (programEvent != eProgramStatusEventType.Stopping) + return; - // Dispose(true); - //}; + Dispose(true); + }; } - + /// /// Thread callback /// @@ -231,10 +231,13 @@ namespace PepperDash.Essentials.Core.Queues if (disposing) { - Debug.Console(2, this, "Disposing..."); - _queue.Clear(); - Enqueue(null); - _worker.Join(); + Debug.Console(2, this, "Disposing..."); + if (_queue != null && !_queue.Disposed) + { + _queue.Clear(); + Enqueue(null); + } + _worker.Abort(); _waitHandle.Close(); } @@ -243,7 +246,7 @@ namespace PepperDash.Essentials.Core.Queues ~GenericQueue() { - Dispose(false); + Dispose(true); } /// @@ -404,13 +407,13 @@ namespace PepperDash_Essentials_Core.Queues _delayEnabled = pacing > 0; _delayTime = pacing; - //CrestronEnvironment.ProgramStatusEventHandler += programEvent => - //{ - // if (programEvent != eProgramStatusEventType.Stopping) - // return; + CrestronEnvironment.ProgramStatusEventHandler += programEvent => + { + if (programEvent != eProgramStatusEventType.Stopping) + return; - // Dispose(true); - //}; + Dispose(true); + }; } /// @@ -479,10 +482,13 @@ namespace PepperDash_Essentials_Core.Queues if (disposing) { - Debug.Console(2, this, "Disposing..."); - _queue.Clear(); - Enqueue(null); - _worker.Join(); + Debug.Console(2, this, "Disposing..."); + if (_queue != null && !_queue.Disposed) + { + _queue.Clear(); + Enqueue(null); + } + _worker.Abort(); _waitHandle.Close(); } @@ -491,7 +497,7 @@ namespace PepperDash_Essentials_Core.Queues ~GenericQueue() { - Dispose(false); + Dispose(true); } ///