Plane.Sdk3/PlaneGcsSdk.Contract_Shared/SynchronizationContextExtensions.cs
2017-02-27 02:02:19 +08:00

33 lines
790 B
C#

using System;
using System.Threading;
namespace Plane
{
public static class SynchronizationContextExtensions
{
public static void Post(this SynchronizationContext syncContext, Action action)
{
if (SynchronizationContext.Current == syncContext)
{
action();
}
else
{
syncContext.Post(state => action(), null);
}
}
public static void Send(this SynchronizationContext syncContext, Action action)
{
if (SynchronizationContext.Current == syncContext)
{
action();
}
else
{
syncContext.Send(state => action(), null);
}
}
}
}