From e7efb5c6cc94c3e1f205098eed3c3babab394803 Mon Sep 17 00:00:00 2001 From: Antoine Aflalo Date: Wed, 13 Oct 2021 14:49:20 -0400 Subject: [PATCH] fix(DeviceLister): Fix crash when device lister is taking too long Fixes SOUNDSWITCH-BJ --- .../Framework/Audio/Lister/CachedAudioDeviceLister.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs b/SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs index 58490cd7d7..f423c6d144 100644 --- a/SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs +++ b/SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs @@ -24,6 +24,7 @@ using SoundSwitch.Framework.NotificationManager; using SoundSwitch.Framework.Threading; using SoundSwitch.Model; +using SoundSwitch.Common.Framework.Dispose; namespace SoundSwitch.Framework.Audio.Lister { @@ -71,13 +72,13 @@ public void Refresh(CancellationToken cancellationToken = default) _refreshSemaphore.Release(); } _context.Warning("Cancellation received."); - throw new OperationCanceledException(cancellationToken); }, null); try { _context.Information("Refreshing all devices"); - using var enumerator = new MMDeviceEnumerator(); + var enumerator = new MMDeviceEnumerator(); + using var _ = enumerator.DisposeOnCancellation(cancellationToken); foreach (var endPoint in enumerator.EnumerateAudioEndPoints(DataFlow.All, _state)) { cancellationToken.ThrowIfCancellationRequested();