@@ -10,86 +10,81 @@ public static class DispatcherQueueExtensions
1010 {
1111 public static Task EnqueueOrInvokeAsync ( this DispatcherQueue ? dispatcher , Func < Task > function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
1212 {
13- return SafetyExtensions . IgnoreExceptions ( ( ) =>
13+ return SafetyExtensions . IgnoreExceptions ( async ( ) =>
1414 {
1515 if ( dispatcher is not null )
1616 {
1717 try
1818 {
19- return dispatcher . EnqueueAsync ( function , priority ) ;
19+ await dispatcher . EnqueueAsync ( function , priority ) ;
2020 }
21- catch ( InvalidOperationException ex )
21+ catch ( InvalidOperationException ex ) when ( ex . Message is "Failed to enqueue the operation" )
2222 {
23- if ( ex . Message is not "Failed to enqueue the operation" )
24- throw ;
2523 }
24+ return ;
2625 }
2726
28- return function ( ) ;
27+ await function ( ) ;
2928 } , App . Logger , typeof ( COMException ) ) ;
3029 }
3130
3231 public static Task < T ? > EnqueueOrInvokeAsync < T > ( this DispatcherQueue ? dispatcher , Func < Task < T > > function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
3332 {
34- return SafetyExtensions . IgnoreExceptions ( ( ) =>
33+ return SafetyExtensions . IgnoreExceptions ( async ( ) =>
3534 {
3635 if ( dispatcher is not null )
3736 {
3837 try
3938 {
40- return dispatcher . EnqueueAsync ( function , priority ) ;
39+ return await dispatcher . EnqueueAsync ( function , priority ) ;
4140 }
42- catch ( InvalidOperationException ex )
41+ catch ( InvalidOperationException ex ) when ( ex . Message is "Failed to enqueue the operation" )
4342 {
44- if ( ex . Message is not "Failed to enqueue the operation" )
45- throw ;
43+ return default ;
4644 }
4745 }
4846
49- return function ( ) ;
47+ return await function ( ) ;
5048 } , App . Logger , typeof ( COMException ) ) ;
5149 }
5250
5351 public static Task EnqueueOrInvokeAsync ( this DispatcherQueue ? dispatcher , Action function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
5452 {
55- return SafetyExtensions . IgnoreExceptions ( ( ) =>
53+ return SafetyExtensions . IgnoreExceptions ( async ( ) =>
5654 {
5755 if ( dispatcher is not null )
5856 {
5957 try
6058 {
61- return dispatcher . EnqueueAsync ( function , priority ) ;
59+ await dispatcher . EnqueueAsync ( function , priority ) ;
6260 }
63- catch ( InvalidOperationException ex )
61+ catch ( InvalidOperationException ex ) when ( ex . Message is "Failed to enqueue the operation" )
6462 {
65- if ( ex . Message is not "Failed to enqueue the operation" )
66- throw ;
6763 }
64+ return ;
6865 }
6966
7067 function ( ) ;
71- return Task . CompletedTask ;
7268 } , App . Logger , typeof ( COMException ) ) ;
7369 }
7470
7571 public static Task < T ? > EnqueueOrInvokeAsync < T > ( this DispatcherQueue ? dispatcher , Func < T > function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
7672 {
77- return SafetyExtensions . IgnoreExceptions ( ( ) =>
73+ return SafetyExtensions . IgnoreExceptions ( async ( ) =>
7874 {
7975 if ( dispatcher is not null )
8076 {
8177 try
8278 {
83- return dispatcher . EnqueueAsync ( function , priority ) ;
79+ return await dispatcher . EnqueueAsync ( function , priority ) ;
8480 }
85- catch ( InvalidOperationException ex )
81+ catch ( InvalidOperationException ex ) when ( ex . Message is "Failed to enqueue the operation" )
8682 {
87- if ( ex . Message is not "Failed to enqueue the operation" )
88- throw ;
83+ return default ;
8984 }
9085 }
9186
92- return Task . FromResult ( function ( ) ) ;
87+ return function ( ) ;
9388 } , App . Logger , typeof ( COMException ) ) ;
9489 }
9590
0 commit comments