Exemple #1
0
        /// <summary>
        /// Fires when the underlying Task is completed.
        /// </summary>
        /// <param name="wrappedTask">The actual result from <see cref="initialDelegate"/>.</param>
        internal void Complete(Task wrappedTask)
        {
            // If we had to synthesize a Task earlier, then wrappedTask is a TaskCompletionSource,
            // which we should now complete.
            if (!(this.wrappedTask is Task))
            {
                this.CompleteTaskSourceFromWrappedTask(wrappedTask, this.wrappedTask);
            }

            using (this.JoinableTaskContext.NoMessagePumpSynchronizationContext.Apply())
            {
                AsyncManualResetEvent queueNeedProcessEvent = null;
                lock (this.JoinableTaskContext.SyncContextLock)
                {
                    if (!this.IsCompleteRequested)
                    {
                        this.IsCompleteRequested = true;

                        if (this.mainThreadQueue != null)
                        {
                            this.mainThreadQueue.Complete();
                        }

                        if (this.threadPoolQueue != null)
                        {
                            this.threadPoolQueue.Complete();
                        }

                        this.OnQueueCompleted();

                        // Always arrange to pulse the event since folks waiting
                        // will likely want to know that the JoinableTask has completed.
                        queueNeedProcessEvent = this.queueNeedProcessEvent;

                        JoinableTaskDependencyGraph.OnTaskCompleted(this);
                    }
                }

                if (queueNeedProcessEvent != null)
                {
                    // We explicitly do this outside our lock.
                    queueNeedProcessEvent.PulseAll();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Fires when the underlying Task is completed.
        /// </summary>
        internal void Complete()
        {
            using (this.Factory.Context.NoMessagePumpSynchronizationContext.Apply())
            {
                AsyncManualResetEvent queueNeedProcessEvent = null;
                lock (this.owner.Context.SyncContextLock)
                {
                    if (!this.IsCompleteRequested)
                    {
                        this.IsCompleteRequested = true;

                        if (this.mainThreadQueue != null)
                        {
                            this.mainThreadQueue.Complete();
                        }

                        if (this.threadPoolQueue != null)
                        {
                            this.threadPoolQueue.Complete();
                        }

                        this.OnQueueCompleted();

                        // Always arrange to pulse the event since folks waiting
                        // will likely want to know that the JoinableTask has completed.
                        queueNeedProcessEvent = this.queueNeedProcessEvent;

                        this.CleanupDependingSynchronousTask();
                    }
                }

                if (queueNeedProcessEvent != null)
                {
                    // We explicitly do this outside our lock.
                    queueNeedProcessEvent.PulseAll();
                }
            }
        }