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 Port;
|
||||||
ComPort.ComPortSpec Spec;
|
ComPort.ComPortSpec Spec;
|
||||||
|
private readonly object _deactivateLock = new object();
|
||||||
|
private bool _isDeactivated;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
|
|
@ -148,7 +150,9 @@ namespace PepperDash.Essentials.Core
|
||||||
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
|
||||||
{
|
{
|
||||||
if (programEventType == eProgramStatusEventType.Stopping)
|
if (programEventType == eProgramStatusEventType.Stopping)
|
||||||
|
{
|
||||||
Deactivate();
|
Deactivate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -157,6 +161,16 @@ namespace PepperDash.Essentials.Core
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool Deactivate()
|
public override bool Deactivate()
|
||||||
{
|
{
|
||||||
|
lock (_deactivateLock)
|
||||||
|
{
|
||||||
|
if (_isDeactivated)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
_isDeactivated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CrestronEnvironment.ProgramStatusEventHandler -= CrestronEnvironment_ProgramStatusEventHandler;
|
||||||
|
|
||||||
if (Port == null)
|
if (Port == null)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue