@@ -13,9 +13,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<T
1313 return SafetyExtensions . IgnoreExceptions ( ( ) =>
1414 {
1515 if ( dispatcher is not null )
16- return dispatcher . EnqueueAsync ( function , priority ) ;
17- else
18- return function ( ) ;
16+ {
17+ try
18+ {
19+ return dispatcher . EnqueueAsync ( function , priority ) ;
20+ }
21+ catch ( InvalidOperationException ex )
22+ {
23+ if ( ex . Message is not "Failed to enqueue the operation" )
24+ throw ;
25+ }
26+ }
27+
28+ return function ( ) ;
1929 } , App . Logger , typeof ( COMException ) ) ;
2030 }
2131
@@ -24,9 +34,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<T
2434 return SafetyExtensions . IgnoreExceptions ( ( ) =>
2535 {
2636 if ( dispatcher is not null )
27- return dispatcher . EnqueueAsync ( function , priority ) ;
28- else
29- return function ( ) ;
37+ {
38+ try
39+ {
40+ return dispatcher . EnqueueAsync ( function , priority ) ;
41+ }
42+ catch ( InvalidOperationException ex )
43+ {
44+ if ( ex . Message is not "Failed to enqueue the operation" )
45+ throw ;
46+ }
47+ }
48+
49+ return function ( ) ;
3050 } , App . Logger , typeof ( COMException ) ) ;
3151 }
3252
@@ -35,12 +55,20 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action
3555 return SafetyExtensions . IgnoreExceptions ( ( ) =>
3656 {
3757 if ( dispatcher is not null )
38- return dispatcher . EnqueueAsync ( function , priority ) ;
39- else
4058 {
41- function ( ) ;
42- return Task . CompletedTask ;
59+ try
60+ {
61+ return dispatcher . EnqueueAsync ( function , priority ) ;
62+ }
63+ catch ( InvalidOperationException ex )
64+ {
65+ if ( ex . Message is not "Failed to enqueue the operation" )
66+ throw ;
67+ }
4368 }
69+
70+ function ( ) ;
71+ return Task . CompletedTask ;
4472 } , App . Logger , typeof ( COMException ) ) ;
4573 }
4674
@@ -49,9 +77,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action
4977 return SafetyExtensions . IgnoreExceptions ( ( ) =>
5078 {
5179 if ( dispatcher is not null )
52- return dispatcher . EnqueueAsync ( function , priority ) ;
53- else
54- return Task . FromResult ( function ( ) ) ;
80+ {
81+ try
82+ {
83+ return dispatcher . EnqueueAsync ( function , priority ) ;
84+ }
85+ catch ( InvalidOperationException ex )
86+ {
87+ if ( ex . Message is not "Failed to enqueue the operation" )
88+ throw ;
89+ }
90+ }
91+
92+ return Task . FromResult ( function ( ) ) ;
5593 } , App . Logger , typeof ( COMException ) ) ;
5694 }
5795
0 commit comments