Skip to content

Commit

Permalink
fix(DeviceLister): Fix crash when device lister is taking too long
Browse files Browse the repository at this point in the history
Fixes SOUNDSWITCH-BJ
  • Loading branch information
Belphemur committed Oct 13, 2021
1 parent ea6048a commit e7efb5c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit e7efb5c

Please sign in to comment.