protected internal override void QueueTask(Task task)
        {
#if !FEATURE_PAL && !FEATURE_CORECLR    // PAL and CoreClr don't support  eventing
            var etwLog = TplEtwProvider.Log;
            if (etwLog.IsEnabled(EventLevel.Verbose, ((EventKeywords)(-1))))
            {
                Task currentTask = Task.InternalCurrent;
                Task creatingTask = task.m_parent;

                etwLog.TaskScheduled(this.Id, currentTask == null ? 0 : currentTask.Id,
                                                 task.Id, creatingTask == null ? 0 : creatingTask.Id,
                                                 (int)task.Options);
            }
#endif

            if ((task.Options & TaskCreationOptions.LongRunning) != 0)
            {
                NativeThreadPool.QueueLongRunningWork(() => task.ExecuteEntry(false));
            }
            else
            {
                // Normal handling for non-LongRunning tasks.
                bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
                ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
            }
        }
Beispiel #2
0
        private static void LongRunningThreadWork(object obj)
        {
            Contract.Requires(obj != null, "TaskScheduler.LongRunningThreadWork: obj is null");
            Task t = obj as Task;

            Contract.Assert(t != null, "TaskScheduler.LongRunningThreadWork: t is null");
            t.ExecuteEntry(false);
        }
 protected bool TryExecuteTask(Task task)
 {
     if (task.Scheduler != this)
     {
         throw new InvalidOperationException("Wrong Task Scheduler");
     }
     return(task.ExecuteEntry(true));
 }
Beispiel #4
0
 protected bool TryExecuteTask(Task task)
 {
     if (task.ExecutingTaskScheduler != this)
     {
         throw new InvalidOperationException(Environment.GetResourceString("TaskScheduler_ExecuteTask_WrongTaskScheduler"));
     }
     return(task.ExecuteEntry(true));
 }
        /// <summary>
        /// Attempts to execute the provided <see cref="System.Threading.Tasks.Task">Task</see>
        /// on this scheduler.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Scheduler implementations are provided with <see cref="System.Threading.Tasks.Task">Task</see>
        /// instances to be executed through either the <see cref="QueueTask"/> method or the
        /// <see cref="TryExecuteTaskInline"/> method. When the scheduler deems it appropriate to run the
        /// provided task, <see cref="TryExecuteTask"/> should be used to do so. TryExecuteTask handles all
        /// aspects of executing a task, including action invocation, exception handling, state management,
        /// and lifecycle control.
        /// </para>
        /// <para>
        /// <see cref="TryExecuteTask"/> must only be used for tasks provided to this scheduler by the .NET
        /// Framework infrastructure. It should not be used to execute arbitrary tasks obtained through
        /// custom mechanisms.
        /// </para>
        /// </remarks>
        /// <param name="task">
        /// A <see cref="System.Threading.Tasks.Task">Task</see> object to be executed.</param>
        /// <exception cref="System.InvalidOperationException">
        /// The <paramref name="task"/> is not associated with this scheduler.
        /// </exception>
        /// <returns>A Boolean that is true if <paramref name="task"/> was successfully executed, false if it
        /// was not. A common reason for execution failure is that the task had previously been executed or
        /// is in the process of being executed by another thread.</returns>
        protected bool TryExecuteTask(Task task)
        {
            if (task.ExecutingTaskScheduler != this)
            {
                throw new InvalidOperationException(SR.TaskScheduler_ExecuteTask_WrongTaskScheduler);
            }

            return(task.ExecuteEntry());
        }
Beispiel #6
0
        protected bool TryExecuteTask(Task task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (task.ExecutingTaskScheduler != this)
            {
                throw new InvalidOperationException("Wrong Task Scheduler");
            }

            return(task.ExecuteEntry(true));
        }
 protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
 {
     if (taskWasPreviouslyQueued && !ThreadPool.TryPopCustomWorkItem((IThreadPoolWorkItem)task))
     {
         return(false);
     }
     try
     {
         return(task.ExecuteEntry(false));
     }
     finally
     {
         if (taskWasPreviouslyQueued)
         {
             this.NotifyWorkItemProgress();
         }
     }
 }
        /// <summary>
        /// This internal function will do this:
        ///   (1) If the task had previously been queued, attempt to pop it and return false if that fails.
        ///   (2) Propagate the return value from Task.ExecuteEntry() back to the caller.
        /// 
        /// IMPORTANT NOTE: TryExecuteTaskInline will NOT throw task exceptions itself. Any wait code path using this function needs
        /// to account for exceptions that need to be propagated, and throw themselves accordingly.
        /// </summary>
        protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
        {
            // If the task was previously scheduled, and we can't pop it, then return false.
            if (taskWasPreviouslyQueued && !ThreadPool.TryPopCustomWorkItem(task))
                return false;

            // Propagate the return value of Task.ExecuteEntry()
            bool rval = false;
            try
            {
                rval = task.ExecuteEntry(false); // handles switching Task.Current etc.
            }
            finally
            {
                //   Only call NWIP() if task was previously queued
                if(taskWasPreviouslyQueued) NotifyWorkItemProgress();
            }

            return rval;
        }
 protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
 {
     if (taskWasPreviouslyQueued && !ThreadPool.TryPopCustomWorkItem(task))
     {
         return false;
     }
     bool flag = false;
     try
     {
         flag = task.ExecuteEntry(false);
     }
     finally
     {
         if (taskWasPreviouslyQueued)
         {
             this.NotifyWorkItemProgress();
         }
     }
     return flag;
 }
        /// <summary>
        /// Schedules a task to the ThreadPool.
        /// </summary>
        /// <param name="task">The task to schedule.</param>
        protected internal override void QueueTask(Task task)
        {
            if (TaskTrace.Enabled)
            {
                Task currentTask  = Task.InternalCurrent;
                Task creatingTask = task.m_parent;

                TaskTrace.TaskScheduled(this.Id, currentTask == null ? 0 : currentTask.Id,
                                        task.Id, creatingTask == null ? 0 : creatingTask.Id,
                                        (int)task.Options);
            }

            if ((task.Options & TaskCreationOptions.LongRunning) != 0)
            {
                ThreadPool.QueueLongRunningWork(() => task.ExecuteEntry(false));
            }
            else
            {
                // Normal handling for non-LongRunning tasks.
                bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
                ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
            }
        }
        /// <summary>
        /// Schedules a task to the ThreadPool.
        /// </summary>
        /// <param name="task">The task to schedule.</param>
        protected internal override void QueueTask(Task task)
        {
            if (TaskTrace.Enabled)
            {
                Task currentTask = Task.InternalCurrent;
                Task creatingTask = task.m_parent;

                TaskTrace.TaskScheduled(this.Id, currentTask == null ? 0 : currentTask.Id,
                                                 task.Id, creatingTask == null ? 0 : creatingTask.Id,
                                                 (int)task.Options);
            }

            if ((task.Options & TaskCreationOptions.LongRunning) != 0)
            {
                ThreadPool.QueueLongRunningWork(() => task.ExecuteEntry(false));
            }
            else
            {
                // Normal handling for non-LongRunning tasks.
                bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
                ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
            }
        }
 protected bool TryExecuteTask(Task task)
 {
     if (task.ExecutingTaskScheduler != this)
     {
         throw new InvalidOperationException(Environment.GetResourceString("TaskScheduler_ExecuteTask_WrongTaskScheduler"));
     }
     return task.ExecuteEntry(true);
 }
        protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
        {
            // If the task was previously scheduled, and we can't pop it, then return false.
#if !PFX_LEGACY_3_5
            if (taskWasPreviouslyQueued && !ThreadPool.TryPopCustomWorkItem(task))
            {
                return false;
            }
#endif
            // Propagate the return value of Task.ExecuteEntry()
            bool rval = false;
            try
            {
#if PFX_LEGACY_3_5
                // 3.5 needs atomic state transitions
                rval = task.ExecuteEntry(true); // calling the TaskBase override here, because it handles switching Task.Current etc.
#else
                rval = task.ExecuteEntry(false); // calling the TaskBase override here, because it handles switching Task.Current etc.
#endif

            }
            finally
            {
                //   Only call NWIP() if task was previously queued
                if(taskWasPreviouslyQueued) NotifyWorkItemProgress();
            }

            return rval;
        }
 protected internal override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
 {
     if ((task.CreationOptions & TaskCreationOptions.LongRunning) != 0)
     {
         // LongRunning task are going to run on a dedicated Thread.
         return false;
     }
     // Propagate the return value of Task.ExecuteEntry()
     bool result;
     try
     {
         result = task.ExecuteEntry(true); // handles switching Task.Current etc.
     }
     finally
     {
         //   Only call NWIP() if task was previously queued
         if (taskWasPreviouslyQueued) NotifyWorkItemProgress();
     }
     return result;
 }
Beispiel #15
0
        static void TaskExecuteWaitCallback(Object obj)
        {
            Task task = (Task)obj;

            task.ExecuteEntry(true);
        }
Beispiel #16
0
        // Token: 0x06004105 RID: 16645 RVA: 0x000F1B80 File Offset: 0x000EFD80
        private static void LongRunningThreadWork(object obj)
        {
            Task task = obj as Task;

            task.ExecuteEntry(false);
        }
Beispiel #17
0
        protected bool TryExecuteTask(Task task)
        {
            if (task.ExecutingTaskScheduler != this)
            {
                throw new InvalidOperationException(SR.TaskScheduler_ExecuteTask_WrongTaskScheduler);
            }

            return task.ExecuteEntry(true);
        }
        // Token: 0x060040FE RID: 16638 RVA: 0x000F1B0C File Offset: 0x000EFD0C
        private static void PostCallback(object obj)
        {
            Task task = (Task)obj;

            task.ExecuteEntry(true);
        }