GetScheduledTasks Method

TaskScheduler.GetScheduledTasks Method

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

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

protected abstract IEnumerable<Task> GetScheduledTasks()

Return Value

Type: System.Collections.Generic.IEnumerable<Task>
An enumerable that allows a debugger to traverse the tasks currently queued to this scheduler.

ExceptionCondition
NotSupportedException

This scheduler is unable to generate a list of queued tasks at this time.

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

For developers implementing a custom debugger, this method shouldn't be called directly, but rather this functionality should be accessed through the internal wrapper method GetScheduledTasksForDebugger: internal Task[] GetScheduledTasksForDebugger(). This method returns an array of tasks, rather than an enumerable. In order to retrieve a list of active schedulers, a debugger may use another internal method: internal static TaskScheduler[] GetTaskSchedulersForDebugger().

This static method returns an array of all active TaskScheduler instances.

GetScheduledTasksForDebugger then may be used on each of these scheduler instances to retrieve the list of scheduled tasks for each.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2016 Microsoft