33 lines
790 B
C#
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|