mirror of https://github.com/AMT-Cheif/Stylet.git
Execute runs delegate synchronously if possible
This commit is contained in:
parent
40c9d4ed88
commit
e37068838a
|
@ -13,7 +13,8 @@ namespace Stylet
|
||||||
|
|
||||||
public static void OnUIThread(Action action)
|
public static void OnUIThread(Action action)
|
||||||
{
|
{
|
||||||
if (SynchronizationContext != null)
|
// If we're already on the given SynchronizationContext, or it hasn't been set, run synchronously
|
||||||
|
if (SynchronizationContext != null && SynchronizationContext != SynchronizationContext.Current)
|
||||||
SynchronizationContext.Post(_ => action(), null);
|
SynchronizationContext.Post(_ => action(), null);
|
||||||
else
|
else
|
||||||
action();
|
action();
|
||||||
|
@ -21,7 +22,8 @@ namespace Stylet
|
||||||
|
|
||||||
public static Task OnUIThreadAsync(Action action)
|
public static Task OnUIThreadAsync(Action action)
|
||||||
{
|
{
|
||||||
if (SynchronizationContext != null)
|
// If we're already on the given SynchronizationContext, or it hasn't been set, run synchronously
|
||||||
|
if (SynchronizationContext != null && SynchronizationContext != SynchronizationContext.Current)
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<object>();
|
var tcs = new TaskCompletionSource<object>();
|
||||||
SynchronizationContext.Post(_ =>
|
SynchronizationContext.Post(_ =>
|
||||||
|
|
Loading…
Reference in New Issue