mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-07-02 10:38:16 +00:00
fix: make ComPortController shutdown deactivation idempotent
This commit is contained in:
parent
a2388acf64
commit
cd8bfcfbdc
1 changed files with 14 additions and 0 deletions
|
|
@ -38,6 +38,8 @@ namespace PepperDash.Essentials.Core
|
|||
|
||||
ComPort Port;
|
||||
ComPort.ComPortSpec Spec;
|
||||
private readonly object _deactivateLock = new object();
|
||||
private bool _isDeactivated;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
|
|
@ -148,8 +150,10 @@ namespace PepperDash.Essentials.Core
|
|||
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
||||
{
|
||||
if (programEventType == eProgramStatusEventType.Stopping)
|
||||
{
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deactivate method
|
||||
|
|
@ -157,6 +161,16 @@ namespace PepperDash.Essentials.Core
|
|||
/// <inheritdoc />
|
||||
public override bool Deactivate()
|
||||
{
|
||||
lock (_deactivateLock)
|
||||
{
|
||||
if (_isDeactivated)
|
||||
return true;
|
||||
|
||||
_isDeactivated = true;
|
||||
}
|
||||
|
||||
CrestronEnvironment.ProgramStatusEventHandler -= CrestronEnvironment_ProgramStatusEventHandler;
|
||||
|
||||
if (Port == null)
|
||||
return true;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue