Skip to content

Commit 785399e

Browse files
committed
perf(device:cache): Force restarting the refresh when job cancelled
1 parent 8b380f1 commit 785399e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

SoundSwitch/Framework/Audio/Lister/CachedAudioDeviceLister.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,16 @@ public void Refresh(CancellationToken cancellationToken = default)
107107
var playbackDevices = new Dictionary<string, DeviceFullInfo>();
108108
var recordingDevices = new Dictionary<string, DeviceFullInfo>();
109109

110-
using var registration = cancellationToken.Register(_ => { _context.Warning("Cancellation received."); }, null);
110+
using var registration = cancellationToken.Register(_ =>
111+
{
112+
_context.Warning("Cancellation received.");
113+
throw new OperationCanceledException("Stop refreshing", cancellationToken);
114+
}, null);
111115

112116
try
113117
{
114118
_context.Information("Refreshing all devices");
115-
using var enumerator = new MMDeviceEnumerator();
119+
var enumerator = new MMDeviceEnumerator();
116120
using var _ = enumerator.DisposeOnCancellation(cancellationToken);
117121
foreach (var endPoint in enumerator.EnumerateAudioEndPoints(DataFlow.All, _state))
118122
{

SoundSwitch/Framework/Audio/Lister/Job/DebounceRefreshJob.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Task OnFailure(JobException exception)
4141
}
4242

4343
public IRetryAction FailRule { get; } = new NoRetry();
44-
public TimeSpan? MaxRuntime { get; } = TimeSpan.FromSeconds(5);
44+
public TimeSpan? MaxRuntime { get; } = TimeSpan.FromSeconds(3);
4545
public string Key { get; }
4646
public TimeSpan DebounceTime { get; } = TimeSpan.FromMilliseconds(175);
4747
}

0 commit comments

Comments
 (0)