internal static void HandleOnCompleted (Task task, Action continuation, bool continueOnSourceContext, InstanceReference instanceReference, IAsyncSetThis thisSetter) { if (continueOnSourceContext && SynchronizationContext.Current != null) { task.ContinueWith(new SynchronizationContextContinuation(continuation, SynchronizationContext.Current, instanceReference, thisSetter)); } else { task.ContinueWith (new ActionContinuation (continuation)); } }
internal ConfiguredTaskAwaiter(Task task, bool continueOnSourceContext, InstanceReference instanceReference) { this.task = task; this.continueOnSourceContext = continueOnSourceContext; this.instanceReference = instanceReference; this.thisSetter = null; if (instanceReference != null) { if (InstanceSynchronizationContext.GetRegisteredActivity(instanceReference) == null) { throw new TaskSchedulerException("ConfiguredTaskAwaiter called while static SynchronizationContext.SetSynchronizationContext(...) is not called."); } } }
public static void SetSynchronizationContext(InstanceReference instanceReference) { if (!(Current is InstanceSynchronizationContext)) { SetSynchronizationContext(new InstanceSynchronizationContext()); } InstanceSynchronizationContext.RegisterActivity(instanceReference); }
public SynchronizationContextContinuation(Action action, SynchronizationContext ctx, InstanceReference instanceReference, IAsyncSetThis thisSetter) { this.action = action; this.ctx = ctx; this.instanceReference = instanceReference; this.thisSetter = thisSetter; }
internal ConfiguredTaskAwaitable(Task task, bool continueOnSourceContext, InstanceReference instanceReference) { awaiter = new ConfiguredTaskAwaiter(task, continueOnSourceContext, instanceReference); }
internal static object GetRegisteredActivity(InstanceReference instanceReference) { var hashCode = instanceReference.GetHashCode(); return registeredInstances.ContainsKey(hashCode) ? registeredInstances.Get(hashCode) : null; }
internal static void RegisterActivity(InstanceReference instanceReference) { var hashCode = instanceReference.GetHashCode(); if (registeredInstances.ContainsKey(hashCode)) registeredInstances.Remove(hashCode); registeredInstances.Put(hashCode, instanceReference.Instance); }