/// <summary>Gets all of the tasks currently scheduled to this scheduler.</summary> /// <returns>An enumerable containing all of the scheduled tasks.</returns> protected override IEnumerable <Task> GetScheduledTasks() { List <Task> list = new List <Task>(); bool flag = false; try { Monitor.TryEnter(this.m_queue, ref flag); if (!flag) { throw new NotSupportedException(); } list.AddRange(this.m_queue.ToArray()); } finally { if (flag) { Monitor.Exit(this.m_queue); } } WorkStealingQueue <Task>[] wsQueues = this.m_wsQueues; for (int i = 0; i < wsQueues.Length; i++) { WorkStealingQueue <Task> workStealingQueue = wsQueues[i]; if (workStealingQueue != null) { list.AddRange(workStealingQueue.ToArray()); } } return(list); }
/// <summary>Gets all of the tasks currently scheduled to this scheduler.</summary> /// <returns>An enumerable containing all of the scheduled tasks.</returns> protected override IEnumerable <Task> GetScheduledTasks() { // Keep track of all of the tasks we find List <Task> tasks = new List <Task>(); // Get all of the global tasks. We use TryEnter so as not to hang // a debugger if the lock is held by a frozen thread. bool lockTaken = false; try { Monitor.TryEnter(m_queue, ref lockTaken); if (lockTaken) { tasks.AddRange(m_queue.ToArray()); } else { throw new NotSupportedException(); } } finally { if (lockTaken) { Monitor.Exit(m_queue); } } // Now get all of the tasks from the work-stealing queues WorkStealingQueue <Task>[] queues = m_wsQueues; for (int i = 0; i < queues.Length; i++) { WorkStealingQueue <Task> wsq = queues[i]; if (wsq != null) { tasks.AddRange(wsq.ToArray()); } } // Return to the debugger all of the collected task instances return(tasks); }