|
4 | 4 |
|
5 | 5 | using System; |
6 | 6 | using System.Threading.Tasks; |
7 | | -using Windows.Foundation.Metadata; |
8 | 7 | using Windows.System; |
9 | 8 |
|
10 | 9 | namespace Microsoft.Toolkit.Uwp.Helpers |
@@ -32,7 +31,7 @@ public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Actio |
32 | 31 | /* Run the function directly when we have thread access. |
33 | 32 | * Also reuse Task.CompletedTask in case of success, |
34 | 33 | * to skip an unnecessary heap allocation for every invocation. */ |
35 | | - if (HasThreadAccess(dispatcher)) |
| 34 | + if (dispatcher.HasThreadAccess) |
36 | 35 | { |
37 | 36 | try |
38 | 37 | { |
@@ -81,7 +80,7 @@ public static Task<T> ExecuteOnUIThreadAsync<T>(this DispatcherQueue dispatcher, |
81 | 80 | throw new ArgumentNullException(nameof(function)); |
82 | 81 | } |
83 | 82 |
|
84 | | - if (HasThreadAccess(dispatcher)) |
| 83 | + if (dispatcher.HasThreadAccess) |
85 | 84 | { |
86 | 85 | try |
87 | 86 | { |
@@ -129,7 +128,7 @@ public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Func< |
129 | 128 | * We don't use ConfigureAwait(false) in this case, in order |
130 | 129 | * to let the caller continue its execution on the same thread |
131 | 130 | * after awaiting the task returned by this function. */ |
132 | | - if (HasThreadAccess(dispatcher)) |
| 131 | + if (dispatcher.HasThreadAccess) |
133 | 132 | { |
134 | 133 | try |
135 | 134 | { |
@@ -188,7 +187,7 @@ public static Task<T> ExecuteOnUIThreadAsync<T>(this DispatcherQueue dispatcher, |
188 | 187 | throw new ArgumentNullException(nameof(function)); |
189 | 188 | } |
190 | 189 |
|
191 | | - if (HasThreadAccess(dispatcher)) |
| 190 | + if (dispatcher.HasThreadAccess) |
192 | 191 | { |
193 | 192 | try |
194 | 193 | { |
@@ -230,10 +229,5 @@ public static Task<T> ExecuteOnUIThreadAsync<T>(this DispatcherQueue dispatcher, |
230 | 229 |
|
231 | 230 | return taskCompletionSource.Task; |
232 | 231 | } |
233 | | - |
234 | | - private static bool HasThreadAccess(DispatcherQueue dispatcher) |
235 | | - { |
236 | | - return ApiInformation.IsMethodPresent("Windows.System.DispatcherQueue", "HasThreadAccess") && dispatcher.HasThreadAccess; |
237 | | - } |
238 | 232 | } |
239 | 233 | } |
0 commit comments