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();