From 4c50f12b42adec7edfdb65d183402d4a8e88ec58 Mon Sep 17 00:00:00 2001 From: hexawyz <8518235+hexawyz@users.noreply.github.com> Date: Sun, 9 Feb 2025 22:57:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20DevQuery=20EnumerateAllAsy?= =?UTF-8?q?nc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DeviceTools/DeviceTools.Core/DeviceQuery.cs | 14 +++++++------- src/Tools/StreamDeckPlayground/MainViewModel.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DeviceTools/DeviceTools.Core/DeviceQuery.cs b/src/DeviceTools/DeviceTools.Core/DeviceQuery.cs index aa2ae35d..c5c6bdfc 100644 --- a/src/DeviceTools/DeviceTools.Core/DeviceQuery.cs +++ b/src/DeviceTools/DeviceTools.Core/DeviceQuery.cs @@ -359,14 +359,14 @@ CancellationToken cancellationToken Span propertyKeys = GetPropertyKeys(properties); SafeDeviceQueryHandle query; - DevQueryCallbackContext> context; + DevQueryCallbackContext> context; filter?.FillExpressions(filterExpressions, true, out count); + var channel = Channel.CreateUnbounded(EnumerateAllChannelOptions); try { - var channel = Channel.CreateUnbounded(EnumerateAllChannelOptions); - context = new(Method.EnumerateAll, channel.Reader); + context = new(Method.EnumerateAll, channel); try { @@ -390,21 +390,21 @@ CancellationToken cancellationToken filter?.ReleaseExpressionResources(); } - return EnumerateAllAsync(query, context, cancellationToken); + return EnumerateAllAsync(query, channel, cancellationToken); } private static async IAsyncEnumerable EnumerateAllAsync ( SafeDeviceQueryHandle queryHandle, - DevQueryCallbackContext> context, + ChannelReader reader, [EnumeratorCancellation] CancellationToken cancellationToken ) { try { - while (await context.State.WaitToReadAsync(cancellationToken).ConfigureAwait(false)) + while (await reader.WaitToReadAsync(cancellationToken).ConfigureAwait(false)) { - while (context.State.TryRead(out var info)) + while (reader.TryRead(out var info)) { yield return info; } diff --git a/src/Tools/StreamDeckPlayground/MainViewModel.cs b/src/Tools/StreamDeckPlayground/MainViewModel.cs index 8dc45ea8..73b1cc23 100644 --- a/src/Tools/StreamDeckPlayground/MainViewModel.cs +++ b/src/Tools/StreamDeckPlayground/MainViewModel.cs @@ -40,9 +40,9 @@ public async Task WatchDevicesAsync(CancellationToken cancellationToken) { try { - foreach + await foreach ( - var device in await DeviceQuery.FindAllAsync + var device in DeviceQuery.EnumerateAllAsync ( DeviceObjectKind.DeviceInterface, Properties.System.Devices.InterfaceClassGuid == DeviceInterfaceClassGuids.Hid &