@@ -36,17 +36,19 @@ public static partial class DispatcherQueueExtensions
36
36
/// <param name="callback">The input <see cref="DispatcherQueueHandler{TState}"/> callback to enqueue.</param>
37
37
/// <param name="state">The input state to capture and pass to the callback.</param>
38
38
/// <returns>Whether or not the task was added to the queue.</returns>
39
+ /// <exception cref="Exception">Thrown when the enqueue operation fails.</exception>
39
40
public static unsafe bool TryEnqueue < TState > ( this DispatcherQueue dispatcherQueue , DispatcherQueueHandler < TState > callback , TState state )
40
41
where TState : class
41
42
{
42
43
IDispatcherQueue * dispatcherQueuePtr = ( IDispatcherQueue * ) ( ( IWinRTObject ) dispatcherQueue ) . NativeObject . ThisPtr ;
43
44
DispatcherQueueProxyHandler * dispatcherQueueHandlerPtr = DispatcherQueueProxyHandler . Create ( callback , state ) ;
44
45
45
- byte result ;
46
+ bool success ;
47
+ int hResult ;
46
48
47
49
try
48
50
{
49
- _ = dispatcherQueuePtr ->TryEnqueue ( dispatcherQueueHandlerPtr , & result ) ;
51
+ hResult = dispatcherQueuePtr ->TryEnqueue ( dispatcherQueueHandlerPtr , ( byte * ) & success ) ;
50
52
51
53
GC . KeepAlive ( dispatcherQueue ) ;
52
54
}
@@ -55,7 +57,12 @@ public static unsafe bool TryEnqueue<TState>(this DispatcherQueue dispatcherQueu
55
57
dispatcherQueueHandlerPtr ->Release ( ) ;
56
58
}
57
59
58
- return result == 0 ;
60
+ if ( hResult != 0 )
61
+ {
62
+ ExceptionHelpers . ThrowExceptionForHR ( hResult ) ;
63
+ }
64
+
65
+ return success ;
59
66
}
60
67
61
68
/// <summary>
@@ -67,17 +74,19 @@ public static unsafe bool TryEnqueue<TState>(this DispatcherQueue dispatcherQueu
67
74
/// <param name="callback">The input <see cref="DispatcherQueueHandler{TState}"/> callback to enqueue.</param>
68
75
/// <param name="state">The input state to capture and pass to the callback.</param>
69
76
/// <returns>Whether or not the task was added to the queue.</returns>
77
+ /// <exception cref="Exception">Thrown when the enqueue operation fails.</exception>
70
78
public static unsafe bool TryEnqueue < TState > ( this DispatcherQueue dispatcherQueue , DispatcherQueuePriority priority , DispatcherQueueHandler < TState > callback , TState state )
71
79
where TState : class
72
80
{
73
81
IDispatcherQueue * dispatcherQueuePtr = ( IDispatcherQueue * ) ( ( IWinRTObject ) dispatcherQueue ) . NativeObject . ThisPtr ;
74
82
DispatcherQueueProxyHandler * dispatcherQueueHandlerPtr = DispatcherQueueProxyHandler . Create ( callback , state ) ;
75
83
76
- byte result ;
84
+ bool success ;
85
+ int hResult ;
77
86
78
87
try
79
88
{
80
- _ = dispatcherQueuePtr ->TryEnqueueWithPriority ( priority , dispatcherQueueHandlerPtr , & result ) ;
89
+ hResult = dispatcherQueuePtr ->TryEnqueueWithPriority ( priority , dispatcherQueueHandlerPtr , ( byte * ) & success ) ;
81
90
82
91
GC . KeepAlive ( dispatcherQueue ) ;
83
92
}
@@ -86,7 +95,12 @@ public static unsafe bool TryEnqueue<TState>(this DispatcherQueue dispatcherQueu
86
95
dispatcherQueueHandlerPtr ->Release ( ) ;
87
96
}
88
97
89
- return result == 0 ;
98
+ if ( hResult != 0 )
99
+ {
100
+ ExceptionHelpers . ThrowExceptionForHR ( hResult ) ;
101
+ }
102
+
103
+ return success ;
90
104
}
91
105
92
106
/// <summary>
0 commit comments