Пример #1
0
		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));
			}
		}
Пример #2
0
            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.");
                    }
                }
			}
Пример #3
0
        public static void SetSynchronizationContext(InstanceReference instanceReference)
        {
            if (!(Current is InstanceSynchronizationContext))
            {
                SetSynchronizationContext(new InstanceSynchronizationContext());
            }

            InstanceSynchronizationContext.RegisterActivity(instanceReference);
        }
Пример #4
0
        public SynchronizationContextContinuation(Action action, SynchronizationContext ctx, InstanceReference instanceReference, IAsyncSetThis thisSetter)
		{
			this.action = action;
			this.ctx = ctx;
            this.instanceReference = instanceReference;
            this.thisSetter = thisSetter;
		}
Пример #5
0
        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);
 }