mscorlib 4.0.0.0 System.Object System.Diagnostics.DebuggerDisplay("Id={Id}") System.Diagnostics.DebuggerTypeProxy(typeof(System.Threading.Tasks.TaskScheduler/TaskSchedulerDebuggerView))

acts as the extension point for all pluggable scheduling logic. This includes mechanisms such as how to schedule a task for execution, and how scheduled tasks should be exposed to debuggers.

For more information and code examples, see Task Schedulers.

Several sample task schedulers are available on Code Gallery: Samples for Parallel Programming with the .NET Framework 4.

Represents an object that handles the low-level work of queuing tasks onto threads.

- Constructor
  4.0.0.0
  To be added.

  Initializes the .

- Property
  4.0.0.0
  System.Threading.Tasks.TaskScheduler To be added.

  When not called from within a task, will return the scheduler.

  For more information, see Task Schedulers.

  Gets the associated with the currently executing task.

- Property
  4.0.0.0
  System.Threading.Tasks.TaskScheduler To be added.

  For more information, see Task Schedulers.

  Gets the default instance that is provided by the .NET Framework.

- Method
  4.0.0.0
  System.Threading.Tasks.TaskScheduler

  All instances queued to the returned scheduler will be executed through a call to the method on that context.

  For more information, see Task Schedulers.

  Creates a associated with the current .

  A associated with the current , as determined by .

- Method
  4.0.0.0
  System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task>

  A class derived from implements this method in order to support integration with debuggers. This method will only be invoked by the .NET Framework when the debugger requests access to the data. The enumerable returned will be traversed by debugging utilities to access the tasks currently queued to this scheduler, enabling the debugger to provide a representation of this information in the user interface.

  It is important to note that, when this method is called, all other threads in the process will be frozen. Therefore, it's important to avoid synchronization with other threads that may lead to blocking. If synchronization is necessary, and you are unable to acquire the lock in this method, then you should throw an exception so that the debugger does not hang. The following example shows one possible approach in C#:

  `protected override IEnumerable<Task> GetScheduledTasks() { bool lockTaken = false; try { Monitor.TryEnter(_syncObj, ref lockTaken); if (lockTaken) { return _tasks.ToArray(); } else throw new NotSupportedException(); } finally { if (lockTaken) Monitor.Exit(_syncObj); }}`

  Additionally, this method and the enumerable returned must not modify any globally visible state.

  The returned enumerable should never be null. If there are currently no queued tasks, an empty enumerable should be returned instead.

  Developers who are implementing custom debuggers shouldn't call this method directly, but should use the internal wrapper method GetScheduledTasksForDebugger instead: internal Task[] GetScheduledTasksForDebugger(). This wrapper method returns an array of tasks instead of an enumerable. To retrieve a list of active schedulers, use the internal method internal static TaskScheduler[] GetTaskSchedulersForDebugger(). This static method returns an array of all active instances. You can then use GetScheduledTasksForDebugger on each scheduler instance to retrieve its list of scheduled tasks.

  For debugger support only, generates an enumerable of instances currently queued to the scheduler waiting to be executed.

  An enumerable that allows a debugger to traverse the tasks currently queued to this scheduler.

- Property
  4.0.0.0
  System.Int32 To be added.

  For more information, see Task Schedulers.

  Gets the unique ID for this .

- Property
  4.0.0.0
  System.Int32 To be added.

  For more information, see Task Schedulers.

  Indicates the maximum concurrency level this is able to support.

- Method
  4.0.0.0
  System.Void ``

  A class derived from implements this method to accept tasks being scheduled on the scheduler.

  A typical implementation would store the task in an internal data structure, which would be serviced by threads that would execute those tasks at some time in the future.

  This method is only meant to be called by the .NET Framework and should not be called directly by the derived class. This is necessary for maintaining the consistency of the system.

  Queues a to the scheduler.

  The to be queued.
- Method
  4.0.0.0
  System.Boolean ``

  For more information, see Task Schedulers.

  This method may execute in a finally block; therefore it should return as quickly as possible so that any resources such as objects can be disposed of in a timely manner.

  Attempts to dequeue a that was previously queued to this scheduler.

  A Boolean denoting whether the argument was successfully dequeued.

  The to be dequeued.
- Method
  4.0.0.0
  System.Boolean ``

  Scheduler implementations are provided with instances to be executed through either the method or the method. When the scheduler deems it appropriate to run the provided task, should be used to do so. TryExecuteTask handles all aspects of executing a task, including action invocation, exception handling, state management, and lifecycle control.

  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.

  Attempts to execute the provided on this scheduler.

  A Boolean that is true if 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.

  A object to be executed.
- Method
  4.0.0.0
  System.Boolean `` ``

  A class derived from 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 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 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.

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

  A Boolean value indicating whether the task was executed inline.

  The to be executed. 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.
- Event
  4.0.0.0
  System.EventHandler<System.Threading.Tasks.UnobservedTaskExceptionEventArgs>

  This application domain-wide event provides a mechanism to prevent exception escalation policy (which, by default, terminates the process) from triggering.

  To make it easier for developers to write asynchronous code based on tasks, the net_v45 changes the default exception behavior for unobserved exceptions. Although unobserved exceptions still raise the exception, the process does not terminate by default. Instead, the exception is handled by the runtime after the event is raised, regardless of whether an event handler observes the exception. This behavior can be configured. Starting with the net_v45, you can use the <ThrowUnobservedTaskExceptions> configuration element to revert to the behavior of the net_v40_long and terminate the process:

  `<configuration> <runtime> <ThrowUnobservedTaskExceptions enabled="true"/> </runtime> </configuration>`

  Occurs when a faulted task's unobserved exception is about to trigger exception escalation policy, which, by default, would terminate the process.