本文整理汇总了C#中System.Threading.Tasks.Task.ExecuteEntry方法的典型用法代码示例。如果您正苦于以下问题:C# Task.ExecuteEntry方法的具体用法?C# Task.ExecuteEntry怎么用?C# Task.ExecuteEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了Task.ExecuteEntry方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: QueueTask
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);
}
}
示例2: TryExecuteTaskInline
/// <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;
}
示例3: TryExecuteTaskInline
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;
}
示例4: QueueTask
/// <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);
}
}
示例5: TryExecuteTask
protected bool TryExecuteTask(Task task)
{
if (task.ExecutingTaskScheduler != this)
{
throw new InvalidOperationException(SR.TaskScheduler_ExecuteTask_WrongTaskScheduler);
}
return task.ExecuteEntry(true);
}
示例6: TryExecuteTask
protected bool TryExecuteTask(Task task)
{
if (task.ExecutingTaskScheduler != this)
{
throw new InvalidOperationException(Environment.GetResourceString("TaskScheduler_ExecuteTask_WrongTaskScheduler"));
}
return task.ExecuteEntry(true);
}
示例7: TryExecuteTaskInline
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;
}
示例8: TryExecuteTaskInline
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;
}