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 &