diff --git a/GamesDat/Telemetry/Sources/UdpSourceBase.cs b/GamesDat/Telemetry/Sources/UdpSourceBase.cs index b032040..0cca15f 100644 --- a/GamesDat/Telemetry/Sources/UdpSourceBase.cs +++ b/GamesDat/Telemetry/Sources/UdpSourceBase.cs @@ -9,6 +9,8 @@ namespace GamesDat.Core.Telemetry.Sources { public abstract class UdpSourceBase : TelemetrySourceBase { + private readonly object _disposeLock = new object(); + private bool _disposed; protected UdpClient _listener; protected IPEndPoint _endpoint; @@ -45,7 +47,25 @@ public override async IAsyncEnumerable ReadContinuousAsync([EnumeratorCancell finally { _isListening = false; - _listener.Dispose(); + } + } + + public override void Dispose() + { + lock (_disposeLock) + { + if (!_disposed) + { + _disposed = true; + try + { + _listener?.Dispose(); + } + finally + { + base.Dispose(); + } + } } }