Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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:
virtual IEnumerable<Task^>^ GetScheduledTasks() abstract

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.

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 TaskScheduler instances. You can then use GetScheduledTasksForDebugger on each scheduler instance to retrieve its list of scheduled tasks.

.NET Framework

Supported in: 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.