Skip to content

Commit

Permalink
🐛 Fix DevQuery EnumerateAllAsync.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexawyz committed Feb 9, 2025
1 parent c95077a commit 4c50f12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/DeviceTools/DeviceTools.Core/DeviceQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ CancellationToken cancellationToken
Span<NativeMethods.DevicePropertyCompoundKey> propertyKeys = GetPropertyKeys(properties);

SafeDeviceQueryHandle query;
DevQueryCallbackContext<ChannelReader<DeviceObjectInformation>> context;
DevQueryCallbackContext<ChannelWriter<DeviceObjectInformation>> context;

filter?.FillExpressions(filterExpressions, true, out count);

var channel = Channel.CreateUnbounded<DeviceObjectInformation>(EnumerateAllChannelOptions);
try
{
var channel = Channel.CreateUnbounded<DeviceObjectInformation>(EnumerateAllChannelOptions);
context = new(Method.EnumerateAll, channel.Reader);
context = new(Method.EnumerateAll, channel);

try
{
Expand All @@ -390,21 +390,21 @@ CancellationToken cancellationToken
filter?.ReleaseExpressionResources();
}

return EnumerateAllAsync(query, context, cancellationToken);
return EnumerateAllAsync(query, channel, cancellationToken);
}

private static async IAsyncEnumerable<DeviceObjectInformation> EnumerateAllAsync
(
SafeDeviceQueryHandle queryHandle,
DevQueryCallbackContext<ChannelReader<DeviceObjectInformation>> context,
ChannelReader<DeviceObjectInformation> 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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tools/StreamDeckPlayground/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand Down

0 comments on commit 4c50f12

Please sign in to comment.