Skip to content

Commit

Permalink
semaphore guard for event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
clemensv committed Sep 5, 2024
1 parent df8a350 commit 193186f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Microsoft.Azure.Relay.Bridge/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,24 @@ public static Config LoadConfig(CommandLineSettings commandLineSettings)
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), $"{azbridge}\\{azbridge}_config.machine.yml");

Config config = LoadConfigFile(machineConfigFileName);
Action onchange = () => { var cfg = LoadConfig(commandLineSettings); config.RaiseChanged(cfg); };
SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
Action onchange = () => {
// if we can't get the semaphore, we're already processing a change
if ( semaphore.Wait(0))
{
// wait a second to make sure the file is done being written/changed
Thread.Sleep(1000);
try
{
Config cfg = LoadConfigFile(machineConfigFileName);
config.RaiseChanged(cfg);
}
finally
{
semaphore.Release();
}
}
};

if (Directory.Exists(Path.GetDirectoryName(machineConfigFileName)))
{
Expand Down

0 comments on commit 193186f

Please sign in to comment.