fix: make ComPortController shutdown deactivation idempotent

This commit is contained in:
copilot-swe-agent[bot] 2026-06-09 17:09:30 +00:00 committed by GitHub
parent a2388acf64
commit cd8bfcfbdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;