3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
+ using System . Runtime . CompilerServices ;
6
7
using System . Threading . Tasks ;
7
8
using Windows . Foundation . Metadata ;
8
9
using Windows . System ;
@@ -67,7 +68,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Action function, Dispatc
67
68
}
68
69
} ) )
69
70
{
70
- taskCompletionSource . SetException ( new InvalidOperationException ( "Failed to enqueue the operation" ) ) ;
71
+ taskCompletionSource . SetException ( GetEnqueueException ( "Failed to enqueue the operation" ) ) ;
71
72
}
72
73
73
74
return taskCompletionSource . Task ;
@@ -116,7 +117,7 @@ static Task<T> TryEnqueueAsync(DispatcherQueue dispatcher, Func<T> function, Dis
116
117
}
117
118
} ) )
118
119
{
119
- taskCompletionSource . SetException ( new InvalidOperationException ( "Failed to enqueue the operation" ) ) ;
120
+ taskCompletionSource . SetException ( GetEnqueueException ( "Failed to enqueue the operation" ) ) ;
120
121
}
121
122
122
123
return taskCompletionSource . Task ;
@@ -149,7 +150,7 @@ public static Task EnqueueAsync(this DispatcherQueue dispatcher, Func<Task> func
149
150
return awaitableResult ;
150
151
}
151
152
152
- return Task . FromException ( new InvalidOperationException ( "The Task returned by function cannot be null." ) ) ;
153
+ return Task . FromException ( GetEnqueueException ( "The Task returned by function cannot be null." ) ) ;
153
154
}
154
155
catch ( Exception e )
155
156
{
@@ -173,7 +174,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func<Task> function, Dis
173
174
}
174
175
else
175
176
{
176
- taskCompletionSource . SetException ( new InvalidOperationException ( "The Task returned by function cannot be null." ) ) ;
177
+ taskCompletionSource . SetException ( GetEnqueueException ( "The Task returned by function cannot be null." ) ) ;
177
178
}
178
179
}
179
180
catch ( Exception e )
@@ -182,7 +183,7 @@ static Task TryEnqueueAsync(DispatcherQueue dispatcher, Func<Task> function, Dis
182
183
}
183
184
} ) )
184
185
{
185
- taskCompletionSource . SetException ( new InvalidOperationException ( "Failed to enqueue the operation" ) ) ;
186
+ taskCompletionSource . SetException ( GetEnqueueException ( "Failed to enqueue the operation" ) ) ;
186
187
}
187
188
188
189
return taskCompletionSource . Task ;
@@ -212,7 +213,7 @@ public static Task<T> EnqueueAsync<T>(this DispatcherQueue dispatcher, Func<Task
212
213
return awaitableResult ;
213
214
}
214
215
215
- return Task . FromException < T > ( new InvalidOperationException ( "The Task returned by function cannot be null." ) ) ;
216
+ return Task . FromException < T > ( GetEnqueueException ( "The Task returned by function cannot be null." ) ) ;
216
217
}
217
218
catch ( Exception e )
218
219
{
@@ -236,7 +237,7 @@ static Task<T> TryEnqueueAsync(DispatcherQueue dispatcher, Func<Task<T>> functio
236
237
}
237
238
else
238
239
{
239
- taskCompletionSource . SetException ( new InvalidOperationException ( "The Task returned by function cannot be null." ) ) ;
240
+ taskCompletionSource . SetException ( GetEnqueueException ( "The Task returned by function cannot be null." ) ) ;
240
241
}
241
242
}
242
243
catch ( Exception e )
@@ -245,13 +246,24 @@ static Task<T> TryEnqueueAsync(DispatcherQueue dispatcher, Func<Task<T>> functio
245
246
}
246
247
} ) )
247
248
{
248
- taskCompletionSource . SetException ( new InvalidOperationException ( "Failed to enqueue the operation" ) ) ;
249
+ taskCompletionSource . SetException ( GetEnqueueException ( "Failed to enqueue the operation" ) ) ;
249
250
}
250
251
251
252
return taskCompletionSource . Task ;
252
253
}
253
254
254
255
return TryEnqueueAsync ( dispatcher , function , priority ) ;
255
256
}
257
+
258
+ /// <summary>
259
+ /// Creates an <see cref="InvalidOperationException"/> to return when an enqueue operation fails.
260
+ /// </summary>
261
+ /// <param name="message">The message of the exception.</param>
262
+ /// <returns>An <see cref="InvalidOperationException"/> with a specified message.</returns>
263
+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
264
+ private static InvalidOperationException GetEnqueueException ( string message )
265
+ {
266
+ return new InvalidOperationException ( message ) ;
267
+ }
256
268
}
257
269
}
0 commit comments