mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-12 12:06:58 +00:00
fix: add mutex to prevent multiple scenarios from running at once
This commit is contained in:
parent
5a9b876d80
commit
d970d806c9
1 changed files with 32 additions and 20 deletions
|
|
@ -5,6 +5,7 @@ using Serilog.Events;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace PepperDash.Essentials.Core
|
||||
{
|
||||
|
|
@ -48,6 +49,8 @@ namespace PepperDash.Essentials.Core
|
|||
|
||||
private int _scenarioChangeDebounceTimeSeconds = 10; // default to 10s
|
||||
|
||||
private Mutex _scenarioChange = new Mutex();
|
||||
|
||||
public EssentialsRoomCombiner(string key, EssentialsRoomCombinerPropertiesConfig props)
|
||||
: base(key)
|
||||
{
|
||||
|
|
@ -205,30 +208,39 @@ namespace PepperDash.Essentials.Core
|
|||
}
|
||||
private set
|
||||
{
|
||||
if (value != _currentScenario)
|
||||
try
|
||||
{
|
||||
// Deactivate the old scenario first
|
||||
if (_currentScenario != null)
|
||||
_scenarioChange.WaitOne();
|
||||
|
||||
if (value != _currentScenario)
|
||||
{
|
||||
_currentScenario.Deactivate();
|
||||
}
|
||||
|
||||
_currentScenario = value;
|
||||
|
||||
// Activate the new scenario
|
||||
if (_currentScenario != null)
|
||||
{
|
||||
_currentScenario.Activate();
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this);
|
||||
}
|
||||
|
||||
var handler = RoomCombinationScenarioChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new EventArgs());
|
||||
// Deactivate the old scenario first
|
||||
if (_currentScenario != null)
|
||||
{
|
||||
_currentScenario.Deactivate();
|
||||
}
|
||||
|
||||
_currentScenario = value;
|
||||
|
||||
// Activate the new scenario
|
||||
if (_currentScenario != null)
|
||||
{
|
||||
_currentScenario.Activate();
|
||||
|
||||
Debug.LogMessage(LogEventLevel.Debug, $"Current Scenario: {_currentScenario.Name}", this);
|
||||
}
|
||||
|
||||
var handler = RoomCombinationScenarioChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_scenarioChange.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue