TaskScheduler.TryExecuteTaskInline Method

Determines whether the provided Task can be executed synchronously in this call, and if it can, executes it.

Namespace:  System.Threading.Tasks
Assembly:  mscorlib (in mscorlib.dll)

protected abstract bool TryExecuteTaskInline(
	Task task,
	bool taskWasPreviouslyQueued
)

Parameters

task
Type: System.Threading.Tasks.Task

The Task to be executed.

taskWasPreviouslyQueued
Type: System.Boolean

A Boolean denoting whether or not task has previously been queued. If this parameter is True, then the task may have been previously queued (scheduled); if False, then the task is known not to have been queued, and this call is being made in order to execute the task inline without queuing it.

Return Value

Type: System.Boolean
A Boolean value indicating whether the task was executed inline.

ExceptionCondition
ArgumentNullException

The task argument is null.

InvalidOperationException

The task was already executed.

A class derived from TaskScheduler implements this function to support inline execution of a task on a thread that initiates a wait on that task object. Inline execution is optional, and the request may be rejected by returning false. However, the more tasks that can be inlined, the better the scheduler will scale. In fact, a scheduler that inlines too little may be prone to deadlocks. A proper implementation should ensure that a request executing under the policies guaranteed by the scheduler can successfully inline. For example, if a scheduler uses a dedicated thread to execute tasks, any inlining requests from that thread should succeed.

If a scheduler decides to perform the inline execution, it should do so by calling to the base TaskScheduler's TryExecuteTask method with the provided task object, propagating the return value. It may also be appropriate for the scheduler to remove an inlined task from its internal data structures if it decides to honor the inlining request. Note, however, that under some circumstances a scheduler may be asked to inline a task that was not previously provided to it with the QueueTask method.

The derived scheduler is responsible for making sure that the calling thread is suitable for executing the given task as far as its own scheduling and execution policies are concerned.

For more information, see Task Schedulers.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft