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