@@ -47,29 +47,7 @@ public static partial class DispatcherQueueExtensions
47
47
public static unsafe bool TryEnqueue < T > ( this DispatcherQueue dispatcherQueue , DispatcherQueueHandler < T > callback , T state )
48
48
where T : class
49
49
{
50
- IDispatcherQueue * dispatcherQueuePtr = ( IDispatcherQueue * ) ( ( IWinRTObject ) dispatcherQueue ) . NativeObject . ThisPtr ;
51
- DispatcherQueueProxyHandler1 * dispatcherQueueHandlerPtr = DispatcherQueueProxyHandler1 . Create ( callback , state ) ;
52
-
53
- bool success ;
54
- int hResult ;
55
-
56
- try
57
- {
58
- hResult = dispatcherQueuePtr ->TryEnqueue ( dispatcherQueueHandlerPtr , ( byte * ) & success ) ;
59
-
60
- GC . KeepAlive ( dispatcherQueue ) ;
61
- }
62
- finally
63
- {
64
- dispatcherQueueHandlerPtr ->Release ( ) ;
65
- }
66
-
67
- if ( hResult != 0 )
68
- {
69
- ExceptionHelpers . ThrowExceptionForHR ( hResult ) ;
70
- }
71
-
72
- return success ;
50
+ return TryEnqueue ( dispatcherQueue , DispatcherQueueProxyHandler1 . Create ( callback , state ) ) ;
73
51
}
74
52
75
53
/// <summary>
@@ -85,29 +63,7 @@ public static unsafe bool TryEnqueue<T>(this DispatcherQueue dispatcherQueue, Di
85
63
public static unsafe bool TryEnqueue < T > ( this DispatcherQueue dispatcherQueue , DispatcherQueuePriority priority , DispatcherQueueHandler < T > callback , T state )
86
64
where T : class
87
65
{
88
- IDispatcherQueue * dispatcherQueuePtr = ( IDispatcherQueue * ) ( ( IWinRTObject ) dispatcherQueue ) . NativeObject . ThisPtr ;
89
- DispatcherQueueProxyHandler1 * dispatcherQueueHandlerPtr = DispatcherQueueProxyHandler1 . Create ( callback , state ) ;
90
-
91
- bool success ;
92
- int hResult ;
93
-
94
- try
95
- {
96
- hResult = dispatcherQueuePtr ->TryEnqueueWithPriority ( priority , dispatcherQueueHandlerPtr , ( byte * ) & success ) ;
97
-
98
- GC . KeepAlive ( dispatcherQueue ) ;
99
- }
100
- finally
101
- {
102
- dispatcherQueueHandlerPtr ->Release ( ) ;
103
- }
104
-
105
- if ( hResult != 0 )
106
- {
107
- ExceptionHelpers . ThrowExceptionForHR ( hResult ) ;
108
- }
109
-
110
- return success ;
66
+ return TryEnqueue ( dispatcherQueue , priority , DispatcherQueueProxyHandler1 . Create ( callback , state ) ) ;
111
67
}
112
68
113
69
/// <summary>
@@ -124,22 +80,52 @@ public static unsafe bool TryEnqueue<T>(this DispatcherQueue dispatcherQueue, Di
124
80
public static unsafe bool TryEnqueue < T1 , T2 > ( this DispatcherQueue dispatcherQueue , DispatcherQueueHandler < T1 , T2 > callback , T1 state1 , T2 state2 )
125
81
where T1 : class
126
82
where T2 : class
83
+ {
84
+ return TryEnqueue ( dispatcherQueue , DispatcherQueueProxyHandler2 . Create ( callback , state1 , state2 ) ) ;
85
+ }
86
+
87
+ /// <summary>
88
+ /// Adds a task to the <see cref="DispatcherQueue"/> which will be executed on the thread associated with it.
89
+ /// </summary>
90
+ /// <typeparam name="T1">The type of the first state to capture.</typeparam>
91
+ /// <typeparam name="T2">The type of the second state to capture.</typeparam>
92
+ /// <param name="dispatcherQueue">The target <see cref="DispatcherQueue"/> to invoke the code on.</param>
93
+ /// <param name="priority"> The desired priority for the callback to schedule.</param>
94
+ /// <param name="callback">The input <see cref="DispatcherQueueHandler{T}"/> callback to enqueue.</param>
95
+ /// <param name="state1">The first input state to capture and pass to the callback.</param>
96
+ /// <param name="state2">The second input state to capture and pass to the callback.</param>
97
+ /// <returns>Whether or not the task was added to the queue.</returns>
98
+ /// <exception cref="Exception">Thrown when the enqueue operation fails.</exception>
99
+ public static unsafe bool TryEnqueue < T1 , T2 > ( this DispatcherQueue dispatcherQueue , DispatcherQueuePriority priority , DispatcherQueueHandler < T1 , T2 > callback , T1 state1 , T2 state2 )
100
+ where T1 : class
101
+ where T2 : class
102
+ {
103
+ return TryEnqueue ( dispatcherQueue , priority , DispatcherQueueProxyHandler2 . Create ( callback , state1 , state2 ) ) ;
104
+ }
105
+
106
+ /// <summary>
107
+ /// Adds a task to the <see cref="DispatcherQueue"/> which will be executed on the thread associated with it.
108
+ /// </summary>
109
+ /// <param name="dispatcherQueue">The target <see cref="DispatcherQueue"/> to invoke the code on.</param>
110
+ /// <param name="dispatcherQueueHandler">The input callback to enqueue.</param>
111
+ /// <returns>Whether or not the task was added to the queue.</returns>
112
+ /// <exception cref="Exception">Thrown when the enqueue operation fails.</exception>
113
+ private static unsafe bool TryEnqueue ( DispatcherQueue dispatcherQueue , IDispatcherQueueHandler * dispatcherQueueHandler )
127
114
{
128
115
IDispatcherQueue * dispatcherQueuePtr = ( IDispatcherQueue * ) ( ( IWinRTObject ) dispatcherQueue ) . NativeObject . ThisPtr ;
129
- DispatcherQueueProxyHandler2 * dispatcherQueueHandlerPtr = DispatcherQueueProxyHandler2 . Create ( callback , state1 , state2 ) ;
130
116
131
117
bool success ;
132
118
int hResult ;
133
119
134
120
try
135
121
{
136
- hResult = dispatcherQueuePtr ->TryEnqueue ( dispatcherQueueHandlerPtr , ( byte * ) & success ) ;
122
+ hResult = dispatcherQueuePtr ->TryEnqueue ( dispatcherQueueHandler , ( byte * ) & success ) ;
137
123
138
124
GC . KeepAlive ( dispatcherQueue ) ;
139
125
}
140
126
finally
141
127
{
142
- dispatcherQueueHandlerPtr ->Release ( ) ;
128
+ dispatcherQueueHandler ->Release ( ) ;
143
129
}
144
130
145
131
if ( hResult != 0 )
@@ -153,34 +139,27 @@ public static unsafe bool TryEnqueue<T1, T2>(this DispatcherQueue dispatcherQueu
153
139
/// <summary>
154
140
/// Adds a task to the <see cref="DispatcherQueue"/> which will be executed on the thread associated with it.
155
141
/// </summary>
156
- /// <typeparam name="T1">The type of the first state to capture.</typeparam>
157
- /// <typeparam name="T2">The type of the second state to capture.</typeparam>
158
142
/// <param name="dispatcherQueue">The target <see cref="DispatcherQueue"/> to invoke the code on.</param>
159
143
/// <param name="priority"> The desired priority for the callback to schedule.</param>
160
- /// <param name="callback">The input <see cref="DispatcherQueueHandler{T}"/> callback to enqueue.</param>
161
- /// <param name="state1">The first input state to capture and pass to the callback.</param>
162
- /// <param name="state2">The second input state to capture and pass to the callback.</param>
144
+ /// <param name="dispatcherQueueHandler">The input callback to enqueue.</param>
163
145
/// <returns>Whether or not the task was added to the queue.</returns>
164
146
/// <exception cref="Exception">Thrown when the enqueue operation fails.</exception>
165
- public static unsafe bool TryEnqueue < T1 , T2 > ( this DispatcherQueue dispatcherQueue , DispatcherQueuePriority priority , DispatcherQueueHandler < T1 , T2 > callback , T1 state1 , T2 state2 )
166
- where T1 : class
167
- where T2 : class
147
+ private static unsafe bool TryEnqueue ( DispatcherQueue dispatcherQueue , DispatcherQueuePriority priority , IDispatcherQueueHandler * dispatcherQueueHandler )
168
148
{
169
149
IDispatcherQueue * dispatcherQueuePtr = ( IDispatcherQueue * ) ( ( IWinRTObject ) dispatcherQueue ) . NativeObject . ThisPtr ;
170
- DispatcherQueueProxyHandler2 * dispatcherQueueHandlerPtr = DispatcherQueueProxyHandler2 . Create ( callback , state1 , state2 ) ;
171
150
172
151
bool success ;
173
152
int hResult ;
174
153
175
154
try
176
155
{
177
- hResult = dispatcherQueuePtr ->TryEnqueueWithPriority ( priority , dispatcherQueueHandlerPtr , ( byte * ) & success ) ;
156
+ hResult = dispatcherQueuePtr ->TryEnqueueWithPriority ( priority , dispatcherQueueHandler , ( byte * ) & success ) ;
178
157
179
158
GC . KeepAlive ( dispatcherQueue ) ;
180
159
}
181
160
finally
182
161
{
183
- dispatcherQueueHandlerPtr ->Release ( ) ;
162
+ dispatcherQueueHandler ->Release ( ) ;
184
163
}
185
164
186
165
if ( hResult != 0 )
0 commit comments