From 36994c17bf5f71f37a5002a51840306fa09fb0ef Mon Sep 17 00:00:00 2001 From: Shadowghost Date: Thu, 17 Nov 2022 11:34:48 +0100 Subject: [PATCH] Apply review suggestions --- Jellyfin.Networking/Manager/NetworkManager.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Jellyfin.Networking/Manager/NetworkManager.cs b/Jellyfin.Networking/Manager/NetworkManager.cs index 4a32423e5e..4a6a4a5766 100644 --- a/Jellyfin.Networking/Manager/NetworkManager.cs +++ b/Jellyfin.Networking/Manager/NetworkManager.cs @@ -34,7 +34,7 @@ namespace Jellyfin.Networking.Manager private readonly IConfigurationManager _configurationManager; - private readonly SemaphoreSlim _networkEvent; + private readonly object _networkEventLock; /// /// Holds the published server URLs and the IPs to use them on. @@ -86,7 +86,7 @@ namespace Jellyfin.Networking.Manager _interfaces = new List(); _macAddresses = new List(); _publishedServerUrls = new Dictionary(); - _networkEvent = new SemaphoreSlim(1, 1); + _networkEventLock = new object(); _remoteAddressFilter = new List(); UpdateSettings(_configurationManager.GetNetworkConfiguration()); @@ -162,16 +162,15 @@ namespace Jellyfin.Networking.Manager /// private void HandleNetworkChange() { - _networkEvent.Wait(); - if (!_eventfire) - { - _logger.LogDebug("Network Address Change Event."); - // As network events tend to fire one after the other only fire once every second. - _eventfire = true; - OnNetworkChange(); + lock(_networkEventLock){ + if (!_eventfire) + { + _logger.LogDebug("Network Address Change Event."); + // As network events tend to fire one after the other only fire once every second. + _eventfire = true; + OnNetworkChange(); + } } - - _networkEvent.Release(); } /// @@ -546,7 +545,6 @@ namespace Jellyfin.Networking.Manager _configurationManager.NamedConfigurationUpdated -= ConfigurationUpdated; NetworkChange.NetworkAddressChanged -= OnNetworkAddressChanged; NetworkChange.NetworkAvailabilityChanged -= OnNetworkAvailabilityChanged; - _networkEvent.Dispose(); } _disposed = true;