@@ -19,7 +19,11 @@ public partial class DeviceMonitor
1919 /// is used to block the <see cref="StartAsync(CancellationToken)"/> method until the <see cref="DeviceMonitorLoopAsync"/>
2020 /// has processed the first list of devices.
2121 /// </summary>
22+ #if NET5_0_OR_GREATER
23+ protected TaskCompletionSource ? FirstDeviceListParsed ;
24+ #else
2225 protected TaskCompletionSource < object ? > ? FirstDeviceListParsed ;
26+ #endif
2327
2428 /// <summary>
2529 /// A <see cref="CancellationToken"/> that can be used to cancel the <see cref="MonitorTask"/>.
@@ -39,11 +43,11 @@ public async Task StartAsync(CancellationToken cancellationToken = default)
3943 {
4044 try
4145 {
42- FirstDeviceListParsed = new TaskCompletionSource < object ? > ( ) ;
46+ FirstDeviceListParsed = new ( ) ;
4347 using CancellationTokenRegistration cancellationTokenRegistration = cancellationToken . Register ( ( ) => FirstDeviceListParsed . SetCanceled ( ) ) ;
4448 MonitorTask = DeviceMonitorLoopAsync ( MonitorTaskCancellationTokenSource . Token ) ;
4549 // Wait for the worker thread to have read the first list of devices.
46- _ = await FirstDeviceListParsed . Task . ConfigureAwait ( false ) ;
50+ await FirstDeviceListParsed . Task . ConfigureAwait ( false ) ;
4751 }
4852 finally
4953 {
@@ -133,7 +137,15 @@ protected virtual async Task DeviceMonitorLoopAsync(CancellationToken cancellati
133137 if ( FirstDeviceListParsed != null )
134138 {
135139 // Switch to the background thread to avoid blocking the caller.
136- _ = Task . Factory . StartNew ( ( ) => FirstDeviceListParsed ? . TrySetResult ( null ) , default , TaskCreationOptions . None , TaskScheduler . Default ) ;
140+ _ = Task . Factory . StartNew (
141+ #if NET5_0_OR_GREATER
142+ ( ) => FirstDeviceListParsed ? . TrySetResult ( ) ,
143+ #else
144+ ( ) => FirstDeviceListParsed ? . TrySetResult ( null ) ,
145+ #endif
146+ default,
147+ TaskCreationOptions . None ,
148+ TaskScheduler . Default ) ;
137149 }
138150 }
139151 catch ( TaskCanceledException ex )
0 commit comments