Exemplo n.º 1
0
        public static void SetSynchronizationContext(InstanceReference instanceReference)
        {
            if (!(Current is InstanceSynchronizationContext))
            {
                SetSynchronizationContext(new InstanceSynchronizationContext());
            }

            InstanceSynchronizationContext.RegisterActivity(instanceReference);
        }
Exemplo n.º 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.");
                    }
                }
            }
Exemplo n.º 3
0
        public void Execute(Task completedTask)
        {
            var activityCtx = ctx as InstanceSynchronizationContext;

            if (activityCtx != null && instanceReference != null)
            {
                var newInstance = InstanceSynchronizationContext.GetRegisteredActivity(instanceReference);
                if (newInstance == null)
                {
                    return; //no need to handle remaining code (including the ctx.Post)
                }
                if (thisSetter != null && newInstance != instanceReference.Instance)
                {
                    thisSetter.SetThis(newInstance);
                }
            }

            ctx.Post(l => ((Action)l)(), action);
        }