Skip to content

Commit b70fb63

Browse files
committed
Removed redundant checks, added nullability annotations
1 parent 83d8475 commit b70fb63

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueExtensions.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
using System;
66
using System.Threading.Tasks;
7-
using Microsoft.Toolkit.Diagnostics;
87
using Windows.System;
98

9+
#nullable enable
10+
1011
namespace Microsoft.Toolkit.Uwp.Extensions
1112
{
1213
/// <summary>
@@ -25,8 +26,6 @@ public static class DispatcherQueueExtensions
2526
/// <remarks>If the current thread has access to <paramref name="dispatcher"/>, <paramref name="function"/> will be invoked directly.</remarks>
2627
public static Task EnqueueAsync(this DispatcherQueue dispatcher, Action function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
2728
{
28-
Guard.IsNotNull(function, nameof(function));
29-
3029
// Run the function directly when we have thread access.
3130
// Also reuse Task.CompletedTask in case of success,
3231
// to skip an unnecessary heap allocation for every invocation.
@@ -46,7 +45,7 @@ public static Task EnqueueAsync(this DispatcherQueue dispatcher, Action function
4645

4746
static Task RunAsync(DispatcherQueue dispatcher, Action function, DispatcherQueuePriority priority)
4847
{
49-
var taskCompletionSource = new TaskCompletionSource<object>();
48+
var taskCompletionSource = new TaskCompletionSource<object?>();
5049

5150
if (!dispatcher.TryEnqueue(priority, () =>
5251
{
@@ -83,8 +82,6 @@ static Task RunAsync(DispatcherQueue dispatcher, Action function, DispatcherQueu
8382
/// <remarks>If the current thread has access to <paramref name="dispatcher"/>, <paramref name="function"/> will be invoked directly.</remarks>
8483
public static Task<T> EnqueueAsync<T>(this DispatcherQueue dispatcher, Func<T> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
8584
{
86-
Guard.IsNotNull(function, nameof(function));
87-
8885
if (dispatcher.HasThreadAccess)
8986
{
9087
try
@@ -133,8 +130,6 @@ static Task<T> RunAsync(DispatcherQueue dispatcher, Func<T> function, Dispatcher
133130
/// <remarks>If the current thread has access to <paramref name="dispatcher"/>, <paramref name="function"/> will be invoked directly.</remarks>
134131
public static Task EnqueueAsync(this DispatcherQueue dispatcher, Func<Task> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
135132
{
136-
Guard.IsNotNull(function, nameof(function));
137-
138133
// If we have thread access, we can retrieve the task directly.
139134
// We don't use ConfigureAwait(false) in this case, in order
140135
// to let the caller continue its execution on the same thread
@@ -158,7 +153,7 @@ public static Task EnqueueAsync(this DispatcherQueue dispatcher, Func<Task> func
158153

159154
static Task RunAsync(DispatcherQueue dispatcher, Func<Task> function, DispatcherQueuePriority priority)
160155
{
161-
var taskCompletionSource = new TaskCompletionSource<object>();
156+
var taskCompletionSource = new TaskCompletionSource<object?>();
162157

163158
if (!dispatcher.TryEnqueue(priority, async () =>
164159
{
@@ -202,8 +197,6 @@ static Task RunAsync(DispatcherQueue dispatcher, Func<Task> function, Dispatcher
202197
/// <remarks>If the current thread has access to <paramref name="dispatcher"/>, <paramref name="function"/> will be invoked directly.</remarks>
203198
public static Task<T> EnqueueAsync<T>(this DispatcherQueue dispatcher, Func<Task<T>> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal)
204199
{
205-
Guard.IsNotNull(function, nameof(function));
206-
207200
if (dispatcher.HasThreadAccess)
208201
{
209202
try

0 commit comments

Comments
 (0)