10 [DebuggerDisplay(
"Id={Id}")]
11 [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskSchedulerDebugView))]
12 [__DynamicallyInvokable]
13 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
17 internal sealed
class SystemThreadingTasks_TaskSchedulerDebugView
21 public int Id => m_taskScheduler.Id;
28 return m_taskScheduler.GetScheduledTasks();
32 public SystemThreadingTasks_TaskSchedulerDebugView(
TaskScheduler scheduler)
34 m_taskScheduler = scheduler;
40 private static readonly
TaskScheduler s_defaultTaskScheduler =
new ThreadPoolTaskScheduler();
42 internal static int s_taskSchedulerIdCounter;
44 private volatile int m_taskSchedulerId;
46 private static EventHandler<UnobservedTaskExceptionEventArgs> _unobservedTaskException;
48 private static readonly
object _unobservedTaskExceptionLockObject =
new object();
52 [__DynamicallyInvokable]
55 [__DynamicallyInvokable]
62 internal virtual bool RequiresAtomicStartTransition =>
true;
66 [__DynamicallyInvokable]
69 [__DynamicallyInvokable]
72 return s_defaultTaskScheduler;
78 [__DynamicallyInvokable]
81 [__DynamicallyInvokable]
85 return internalCurrent ??
Default;
93 Task internalCurrent =
Task.InternalCurrent;
98 return internalCurrent.ExecutingTaskScheduler;
104 [__DynamicallyInvokable]
107 [__DynamicallyInvokable]
110 if (m_taskSchedulerId == 0)
120 return m_taskSchedulerId;
125 [__DynamicallyInvokable]
129 [__DynamicallyInvokable]
135 lock (_unobservedTaskExceptionLockObject)
137 _unobservedTaskException = (EventHandler<UnobservedTaskExceptionEventArgs>)
Delegate.
Combine(_unobservedTaskException, value);
142 [__DynamicallyInvokable]
145 lock (_unobservedTaskExceptionLockObject)
147 _unobservedTaskException = (EventHandler<UnobservedTaskExceptionEventArgs>)
Delegate.
Remove(_unobservedTaskException, value);
156 [__DynamicallyInvokable]
166 [__DynamicallyInvokable]
173 [__DynamicallyInvokable]
176 [SecuritySafeCritical]
177 internal bool TryRunInline(
Task task,
bool taskWasPreviouslyQueued)
179 TaskScheduler executingTaskScheduler = task.ExecutingTaskScheduler;
180 if (executingTaskScheduler !=
this && executingTaskScheduler !=
null)
182 return executingTaskScheduler.TryRunInline(task, taskWasPreviouslyQueued);
184 StackGuard currentStackGuard;
185 if (executingTaskScheduler ==
null || task.m_action ==
null || task.IsDelegateInvoked || task.
IsCanceled || !(currentStackGuard = Task.CurrentStackGuard).TryBeginInliningScope())
192 task.FireTaskScheduledIfNeeded(
this);
197 currentStackGuard.EndInliningScope();
199 if (flag && !task.IsDelegateInvoked && !task.
IsCanceled)
201 throw new InvalidOperationException(Environment.GetResourceString(
"TaskScheduler_InconsistentStateAfterTryExecuteTaskInline"));
211 [__DynamicallyInvokable]
217 internal virtual void NotifyWorkItemProgress()
222 internal void InternalQueueTask(Task task)
224 task.FireTaskScheduledIfNeeded(
this);
229 [__DynamicallyInvokable]
234 AddToActiveTaskSchedulers();
238 private void AddToActiveTaskSchedulers()
241 if (conditionalWeakTable ==
null)
244 conditionalWeakTable = s_activeTaskSchedulers;
246 conditionalWeakTable.
Add(
this,
null);
252 [__DynamicallyInvokable]
255 return new SynchronizationContextTaskScheduler();
263 [__DynamicallyInvokable]
266 if (task.ExecutingTaskScheduler !=
this)
270 return task.ExecuteEntry(bPreventDoubleExecution:
true);
275 lock (_unobservedTaskExceptionLockObject)
277 _unobservedTaskException?.Invoke(sender, ueea);
282 internal Task[] GetScheduledTasksForDebugger()
285 if (scheduledTasks ==
null)
289 Task[] array = scheduledTasks as Task[];
294 Task[] array2 = array;
295 foreach (Task task
in array2)
303 internal static TaskScheduler[] GetTaskSchedulersForDebugger()
305 if (s_activeTaskSchedulers ==
null)
309 s_defaultTaskScheduler
313 if (!keys.
Contains(s_defaultTaskScheduler))
315 keys.
Add(s_defaultTaskScheduler);
322 int id = taskScheduler.Id;
static TaskScheduler?? Current
Gets the T:System.Threading.Tasks.TaskScheduler associated with the currently executing task.
Provides data for the event that is raised when a faulted T:System.Threading.Tasks....
static void PrepareContractedDelegate(Delegate d)
Provides a way for applications to dynamically prepare T:System.AppDomain event delegates.
abstract IEnumerable< Task > GetScheduledTasks()
For debugger support only, generates an enumerable of T:System.Threading.Tasks.Task instances current...
void Add(TKey key, TValue value)
Adds a key to the table.
TaskScheduler()
Initializes the T:System.Threading.Tasks.TaskScheduler.
Represents an object that handles the low-level work of queuing tasks onto threads.
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
virtual int MaximumConcurrencyLevel
Indicates the maximum concurrency level this T:System.Threading.Tasks.TaskScheduler is able to suppor...
void CopyTo(T[] array, int arrayIndex)
Copies the elements of the T:System.Collections.Generic.ICollection`1 to an T:System....
static Delegate Remove(Delegate source, Delegate value)
Removes the last occurrence of the invocation list of a delegate from the invocation list of another ...
abstract bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
Determines whether the provided T:System.Threading.Tasks.Task can be executed synchronously in this c...
static Delegate Combine(Delegate a, Delegate b)
Concatenates the invocation lists of two delegates.
static TaskScheduler FromCurrentSynchronizationContext()
Creates a T:System.Threading.Tasks.TaskScheduler associated with the current T:System....
Defines methods to manipulate generic collections.
TaskCreationOptions
Specifies flags that control optional behavior for the creation and execution of tasks.
static TaskScheduler Default
Gets the default T:System.Threading.Tasks.TaskScheduler instance that is provided by the ....
SecurityAction
Specifies the security actions that can be performed using declarative security.
static EventHandler< UnobservedTaskExceptionEventArgs > UnobservedTaskException
Occurs when a faulted task's unobserved exception is about to trigger exception escalation policy,...
Provides information about, and means to manipulate, the current environment and platform....
static bool IsAttached
Gets a value that indicates whether a debugger is attached to the process.
Represents a collection that can contain many different types of permissions.
int Id
Gets the unique ID for this T:System.Threading.Tasks.TaskScheduler.
bool Contains(T item)
Determines whether the T:System.Collections.Generic.ICollection`1 contains a specific value.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Enables compilers to dynamically attach object fields to managed objects.
static int Increment(ref int location)
Increments a specified variable and stores the result, as an atomic operation.
TaskCreationOptions CreationOptions
Gets the T:System.Threading.Tasks.TaskCreationOptions used to create this task.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Enables communication with a debugger. This class cannot be inherited.
abstract internal void QueueTask(Task task)
Queues a T:System.Threading.Tasks.Task to the scheduler.
int Count
Gets the number of elements contained in the T:System.Collections.Generic.ICollection`1.
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
virtual internal bool TryDequeue(Task task)
Attempts to dequeue a T:System.Threading.Tasks.Task that was previously queued to this scheduler.
bool TryExecuteTask(Task task)
Attempts to execute the provided T:System.Threading.Tasks.Task on this scheduler.
The exception that is thrown when a method call is invalid for the object's current state.
T [] ToArray()
Copies the elements of the T:System.Collections.Generic.List`1 to a new array.
Provides atomic operations for variables that are shared by multiple threads.
void Add(T item)
Adds an item to the T:System.Collections.Generic.ICollection`1.
bool IsCanceled
Gets whether this T:System.Threading.Tasks.Task instance has completed execution due to being cancele...
Represents an asynchronous operation that can return a value.
Provides a set of static methods and properties that provide support for compilers....