@@ -13,9 +13,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<T
13
13
return SafetyExtensions . IgnoreExceptions ( ( ) =>
14
14
{
15
15
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 ( ) ;
19
29
} , App . Logger , typeof ( COMException ) ) ;
20
30
}
21
31
@@ -24,9 +34,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Func<T
24
34
return SafetyExtensions . IgnoreExceptions ( ( ) =>
25
35
{
26
36
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 ( ) ;
30
50
} , App . Logger , typeof ( COMException ) ) ;
31
51
}
32
52
@@ -35,12 +55,20 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action
35
55
return SafetyExtensions . IgnoreExceptions ( ( ) =>
36
56
{
37
57
if ( dispatcher is not null )
38
- return dispatcher . EnqueueAsync ( function , priority ) ;
39
- else
40
58
{
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
+ }
43
68
}
69
+
70
+ function ( ) ;
71
+ return Task . CompletedTask ;
44
72
} , App . Logger , typeof ( COMException ) ) ;
45
73
}
46
74
@@ -49,9 +77,19 @@ public static Task EnqueueOrInvokeAsync(this DispatcherQueue? dispatcher, Action
49
77
return SafetyExtensions . IgnoreExceptions ( ( ) =>
50
78
{
51
79
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 ( ) ) ;
55
93
} , App . Logger , typeof ( COMException ) ) ;
56
94
}
57
95
0 commit comments