Beispiel #1
0
        internal void OnQueueCompleted()
        {
            if (this.IsCompleted)
            {
                // Note this code may execute more than once, as multiple queue completion
                // notifications come in.
                this.owner.Context.OnJoinableTaskCompleted(this);

                foreach (var collection in this.collectionMembership)
                {
                    collection.Remove(this);
                }

                if (this.mainThreadJobSyncContext != null)
                {
                    this.mainThreadJobSyncContext.OnCompleted();
                }

                if (this.threadPoolJobSyncContext != null)
                {
                    this.threadPoolJobSyncContext.OnCompleted();
                }

                this.nestingFactories = default(ListOfOftenOne <JoinableTaskFactory>);
                this.initialDelegate  = null;
                this.state           |= JoinableTaskFlags.CompleteFinalized;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Adds the specified flags to the <see cref="state"/> field.
 /// </summary>
 private void AddStateFlags(JoinableTaskFlags flags)
 {
     // Try to avoid taking a lock if the flags are already set appropriately.
     if ((this.state & flags) != flags)
     {
         using (this.Factory.Context.NoMessagePumpSynchronizationContext.Apply())
         {
             lock (this.owner.Context.SyncContextLock)
             {
                 this.state |= flags;
             }
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JoinableTask"/> class.
        /// </summary>
        /// <param name="owner">The instance that began the async operation.</param>
        /// <param name="synchronouslyBlocking">A value indicating whether the launching thread will synchronously block for this job's completion.</param>
        /// <param name="creationOptions">The <see cref="JoinableTaskCreationOptions"/> used to customize the task's behavior.</param>
        /// <param name="initialDelegate">The entry method's info for diagnostics.</param>
        internal JoinableTask(JoinableTaskFactory owner, bool synchronouslyBlocking, JoinableTaskCreationOptions creationOptions, Delegate initialDelegate)
        {
            Requires.NotNull(owner, nameof(owner));

            this.owner = owner;
            if (synchronouslyBlocking)
            {
                this.state |= JoinableTaskFlags.StartedSynchronously | JoinableTaskFlags.CompletingSynchronously;
            }

            if (owner.Context.IsOnMainThread)
            {
                this.state |= JoinableTaskFlags.StartedOnMainThread;
                if (synchronouslyBlocking)
                {
                    this.state |= JoinableTaskFlags.SynchronouslyBlockingMainThread;
                }
            }

            this.creationOptions = creationOptions;
            this.owner.Context.OnJoinableTaskStarted(this);
            this.initialDelegate = initialDelegate;
        }