44
55using System ;
66using System . Threading . Tasks ;
7+ using Microsoft . Toolkit . Diagnostics ;
78using Windows . System ;
89
910namespace Microsoft . Toolkit . Uwp . Helpers
@@ -23,10 +24,7 @@ public static class DispatcherQueueHelper
2324 /// <remarks>If the current thread has UI access, <paramref name="function"/> will be invoked directly.</remarks>
2425 public static Task ExecuteOnUIThreadAsync ( this DispatcherQueue dispatcher , Action function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
2526 {
26- if ( function is null )
27- {
28- throw new ArgumentNullException ( nameof ( function ) ) ;
29- }
27+ Guard . IsNotNull ( function , nameof ( function ) ) ;
3028
3129 // Run the function directly when we have thread access.
3230 // Also reuse Task.CompletedTask in case of success,
@@ -75,10 +73,7 @@ public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Actio
7573 /// <remarks>If the current thread has UI access, <paramref name="function"/> will be invoked directly.</remarks>
7674 public static Task < T > ExecuteOnUIThreadAsync < T > ( this DispatcherQueue dispatcher , Func < T > function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
7775 {
78- if ( function is null )
79- {
80- throw new ArgumentNullException ( nameof ( function ) ) ;
81- }
76+ Guard . IsNotNull ( function , nameof ( function ) ) ;
8277
8378 if ( dispatcher . HasThreadAccess )
8479 {
@@ -119,10 +114,7 @@ public static Task<T> ExecuteOnUIThreadAsync<T>(this DispatcherQueue dispatcher,
119114 /// <remarks>If the current thread has UI access, <paramref name="function"/> will be invoked directly.</remarks>
120115 public static Task ExecuteOnUIThreadAsync ( this DispatcherQueue dispatcher , Func < Task > function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
121116 {
122- if ( function is null )
123- {
124- throw new ArgumentNullException ( nameof ( function ) ) ;
125- }
117+ Guard . IsNotNull ( function , nameof ( function ) ) ;
126118
127119 // If we have thread access, we can retrieve the task directly.
128120 // We don't use ConfigureAwait(false) in this case, in order
@@ -182,10 +174,7 @@ public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Func<
182174 /// <remarks>If the current thread has UI access, <paramref name="function"/> will be invoked directly.</remarks>
183175 public static Task < T > ExecuteOnUIThreadAsync < T > ( this DispatcherQueue dispatcher , Func < Task < T > > function , DispatcherQueuePriority priority = DispatcherQueuePriority . Normal )
184176 {
185- if ( function is null )
186- {
187- throw new ArgumentNullException ( nameof ( function ) ) ;
188- }
177+ Guard . IsNotNull ( function , nameof ( function ) ) ;
189178
190179 if ( dispatcher . HasThreadAccess )
191180 {
0 commit comments