Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

56 lines
1.9 KiB
C#

//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities
{
using System.Runtime;
using System.Threading;
static class SynchronizationContextHelper
{
static WFDefaultSynchronizationContext defaultContext;
public static SynchronizationContext GetDefaultSynchronizationContext()
{
if (SynchronizationContextHelper.defaultContext == null)
{
SynchronizationContextHelper.defaultContext = new WFDefaultSynchronizationContext();
}
return SynchronizationContextHelper.defaultContext;
}
public static SynchronizationContext CloneSynchronizationContext(SynchronizationContext context)
{
Fx.Assert(context != null, "null context parameter");
WFDefaultSynchronizationContext wfDefaultContext = context as WFDefaultSynchronizationContext;
if (wfDefaultContext != null)
{
Fx.Assert(SynchronizationContextHelper.defaultContext != null, "We must have set the static member by now!");
return SynchronizationContextHelper.defaultContext;
}
else
{
return context.CreateCopy();
}
}
class WFDefaultSynchronizationContext : SynchronizationContext
{
public WFDefaultSynchronizationContext()
{
}
public override void Post(SendOrPostCallback d, object state)
{
ActionItem.Schedule(delegate(object s) { d(s); }, state);
}
public override void Send(SendOrPostCallback d, object state)
{
d(state);
}
}
}
}