diff --git a/Stylet/Execute.cs b/Stylet/Execute.cs
index 19be3f6..1e61833 100644
--- a/Stylet/Execute.cs
+++ b/Stylet/Execute.cs
@@ -84,6 +84,7 @@ namespace Stylet
///
/// Dispatches the given action to be run on the UI thread asynchronously, even if the current thread is the UI thread
///
+ /// Action to run on the UI thread
public static void PostToUIThread(Action action)
{
EnsureDispatcher();
@@ -93,9 +94,29 @@ namespace Stylet
action();
}
+ ///
+ /// Dispatches the given action to be run on the UI thread asynchronously, and returns a task which completes when the action completes, even if the current thread is the UI thread
+ ///
+ /// Action to run on the UI thread
+ /// Task which completes when the action has been run
+ public static Task PostToUIThreadAsync(Action action)
+ {
+ EnsureDispatcher();
+ if (!TestExecuteSynchronously)
+ {
+ return PostOnUIThreadInternalAsync(action);
+ }
+ else
+ {
+ action();
+ return Task.FromResult(false);
+ }
+ }
+
///
/// Dispatches the given action to be run on the UI thread asynchronously, or runs it synchronously if the current thread is the UI thread
///
+ /// Action to run on the UI thread
public static void OnUIThread(Action action)
{
EnsureDispatcher();
@@ -108,6 +129,7 @@ namespace Stylet
///
/// Dispatches the given action to be run on the UI thread and blocks until it completes, or runs it synchronously if the current thread is the UI thread
///
+ /// Action to run on the UI thread
public static void OnUIThreadSync(Action action)
{
EnsureDispatcher();
@@ -138,25 +160,14 @@ namespace Stylet
///
/// Dispatches the given action to be run on the UI thread and returns a task that completes when the action completes, or runs it synchronously if the current thread is the UI thread
///
+ /// Action to run on the UI thread
+ /// Task which completes when the action has been run
public static Task OnUIThreadAsync(Action action)
{
EnsureDispatcher();
if (!TestExecuteSynchronously && !Dispatcher.IsCurrent)
{
- var tcs = new TaskCompletionSource