14 [DebuggerTypeProxy(typeof(SystemThreadingTasks_FutureDebugView<>))]
15 [DebuggerDisplay(
"Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}, Result = {DebuggerDisplayResultDescription}")]
16 [__DynamicallyInvokable]
17 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
20 internal TResult m_result;
26 private string DebuggerDisplayResultDescription
30 if (!base.IsRanToCompletion)
32 return Environment.GetResourceString(
"TaskT_DebuggerNoResult");
34 return string.Concat(m_result);
38 private string DebuggerDisplayMethodDescription
43 if ((
object)@delegate ==
null)
47 return @delegate.
Method.ToString();
55 [__DynamicallyInvokable]
58 [__DynamicallyInvokable]
61 if (!base.IsWaitNotificationEnabledOrNotRanToCompletion)
65 return GetResultCore(waitCompletionNotification:
true);
69 internal TResult ResultOnSuccess => m_result;
73 [__DynamicallyInvokable]
76 [__DynamicallyInvokable]
88 : base(state, options, promiseStyle: true)
92 internal Task(TResult result)
98 internal Task(
bool canceled, TResult result,
TaskCreationOptions creationOptions, CancellationToken ct)
99 : base(canceled, creationOptions, ct)
111 [__DynamicallyInvokable]
112 public Task(Func<TResult>
function)
115 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
116 PossiblyCaptureContext(ref stackMark);
125 [__DynamicallyInvokable]
129 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
130 PossiblyCaptureContext(ref stackMark);
139 [__DynamicallyInvokable]
143 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
144 PossiblyCaptureContext(ref stackMark);
155 [__DynamicallyInvokable]
157 : this(function,
Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.
None, (
TaskScheduler)null)
159 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
160 PossiblyCaptureContext(ref stackMark);
168 [__DynamicallyInvokable]
169 public Task(Func<object, TResult>
function,
object state)
172 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
173 PossiblyCaptureContext(ref stackMark);
183 [__DynamicallyInvokable]
187 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
188 PossiblyCaptureContext(ref stackMark);
198 [__DynamicallyInvokable]
202 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
203 PossiblyCaptureContext(ref stackMark);
215 [__DynamicallyInvokable]
217 : this((
Delegate)function, state,
Task.InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.
None, (
TaskScheduler)null)
219 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
220 PossiblyCaptureContext(ref stackMark);
224 : this(valueSelector, parent, cancellationToken, creationOptions, internalOptions, scheduler)
226 PossiblyCaptureContext(ref stackMark);
229 internal Task(Func<TResult> valueSelector, Task parent,
CancellationToken cancellationToken,
TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
230 : base(valueSelector, null, parent, cancellationToken, creationOptions, internalOptions, scheduler)
232 if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
238 internal Task(Func<object, TResult> valueSelector,
object state, Task parent, CancellationToken cancellationToken,
TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark)
239 : this((Delegate)valueSelector, state, parent, cancellationToken, creationOptions, internalOptions, scheduler)
241 PossiblyCaptureContext(ref stackMark);
244 internal Task(Delegate valueSelector,
object state, Task parent, CancellationToken cancellationToken,
TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
245 : base(valueSelector, state, parent, cancellationToken, creationOptions, internalOptions, scheduler)
247 if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
249 throw new ArgumentOutOfRangeException(
"creationOptions", Environment.GetResourceString(
"TaskT_ctor_SelfReplicating"));
253 internal static Task<TResult> StartNew(Task parent, Func<TResult>
function, CancellationToken cancellationToken,
TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark)
255 if (
function ==
null)
257 throw new ArgumentNullException(
"function");
259 if (scheduler ==
null)
261 throw new ArgumentNullException(
"scheduler");
263 if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
265 throw new ArgumentOutOfRangeException(
"creationOptions", Environment.GetResourceString(
"TaskT_ctor_SelfReplicating"));
267 Task<TResult> task =
new Task<TResult>(
function, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler, ref stackMark);
268 task.ScheduleAndStart(needsProtection:
false);
272 internal static Task<TResult> StartNew(Task parent, Func<object, TResult>
function,
object state, CancellationToken cancellationToken,
TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, ref StackCrawlMark stackMark)
274 if (
function ==
null)
276 throw new ArgumentNullException(
"function");
278 if (scheduler ==
null)
280 throw new ArgumentNullException(
"scheduler");
282 if ((internalOptions & InternalTaskOptions.SelfReplicating) != 0)
284 throw new ArgumentOutOfRangeException(
"creationOptions", Environment.GetResourceString(
"TaskT_ctor_SelfReplicating"));
286 Task<TResult> task =
new Task<TResult>(
function, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler, ref stackMark);
287 task.ScheduleAndStart(needsProtection:
false);
291 internal bool TrySetResult(TResult result)
293 if (base.IsCompleted)
297 if (AtomicStateUpdate(67108864, 90177536))
300 Interlocked.Exchange(ref m_stateFlags, m_stateFlags | 0x1000000);
301 m_contingentProperties?.SetCompleted();
308 internal void DangerousSetResult(TResult result)
310 if (m_parent !=
null)
312 bool flag = TrySetResult(result);
316 m_stateFlags |= 16777216;
319 internal TResult GetResultCore(
bool waitCompletionNotification)
321 if (!base.IsCompleted)
323 InternalWait(-1,
default(CancellationToken));
325 if (waitCompletionNotification)
327 NotifyDebuggerOfWaitCompletionIfNecessary();
329 if (!base.IsRanToCompletion)
331 ThrowIfExceptional(includeTaskCanceledExceptions:
true);
336 internal bool TrySetException(
object exceptionObject)
339 EnsureContingentPropertiesInitialized(needsProtection:
true);
340 if (AtomicStateUpdate(67108864, 90177536))
342 AddException(exceptionObject);
343 Finish(bUserDelegateExecuted:
false);
349 internal bool TrySetCanceled(CancellationToken tokenToRecord)
351 return TrySetCanceled(tokenToRecord,
null);
354 internal bool TrySetCanceled(CancellationToken tokenToRecord,
object cancellationException)
357 if (AtomicStateUpdate(67108864, 90177536))
359 RecordInternalCancellationRequest(tokenToRecord, cancellationException);
360 CancellationCleanupLogic();
366 internal override void InnerInvoke()
368 Func<TResult> func = m_action as Func<TResult>;
374 Func<object, TResult> func2 = m_action as Func<object, TResult>;
377 m_result = func2(m_stateObject);
383 [__DynamicallyInvokable]
392 [__DynamicallyInvokable]
404 [__DynamicallyInvokable]
407 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
418 [__DynamicallyInvokable]
421 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
432 [__DynamicallyInvokable]
435 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
447 [__DynamicallyInvokable]
450 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
464 [__DynamicallyInvokable]
467 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
468 return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark);
473 if (continuationAction ==
null)
477 if (scheduler ==
null)
481 Task.CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
482 Task task =
new ContinuationTaskFromResultTask<TResult>(
this, continuationAction,
null, creationOptions, internalOptions, ref stackMark);
483 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
493 [__DynamicallyInvokable]
496 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
508 [__DynamicallyInvokable]
511 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
523 [__DynamicallyInvokable]
526 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
538 [__DynamicallyInvokable]
541 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
557 [__DynamicallyInvokable]
560 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
561 return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions, ref stackMark);
566 if (continuationAction ==
null)
570 if (scheduler ==
null)
574 Task.CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
575 Task task =
new ContinuationTaskFromResultTask<TResult>(
this, continuationAction, state, creationOptions, internalOptions, ref stackMark);
576 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
587 [__DynamicallyInvokable]
590 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
602 [__DynamicallyInvokable]
605 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
617 [__DynamicallyInvokable]
620 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
633 [__DynamicallyInvokable]
636 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
651 [__DynamicallyInvokable]
654 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
655 return ContinueWith(continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark);
660 if (continuationFunction ==
null)
664 if (scheduler ==
null)
668 Task.CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
669 Task<TNewResult> task =
new ContinuationResultTaskFromResultTask<TResult, TNewResult>(
this, continuationFunction,
null, creationOptions, internalOptions, ref stackMark);
670 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
681 [__DynamicallyInvokable]
684 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
697 [__DynamicallyInvokable]
700 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
713 [__DynamicallyInvokable]
716 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
729 [__DynamicallyInvokable]
732 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
749 [__DynamicallyInvokable]
752 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
753 return ContinueWith(continuationFunction, state, scheduler, cancellationToken, continuationOptions, ref stackMark);
758 if (continuationFunction ==
null)
762 if (scheduler ==
null)
766 Task.CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
767 Task<TNewResult> task =
new ContinuationResultTaskFromResultTask<TResult, TNewResult>(
this, continuationFunction, state, creationOptions, internalOptions, ref stackMark);
768 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
773 [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskDebugView))]
774 [DebuggerDisplay(
"Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}")]
775 [__DynamicallyInvokable]
776 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
777 public class Task : IThreadPoolWorkItem, IAsyncResult, IDisposable
779 internal class ContingentProperties
781 internal ExecutionContext m_capturedContext;
783 internal volatile ManualResetEventSlim m_completionEvent;
785 internal volatile TaskExceptionHolder m_exceptionsHolder;
787 internal CancellationToken m_cancellationToken;
789 internal Shared<CancellationTokenRegistration> m_cancellationRegistration;
791 internal volatile int m_internalCancellationRequested;
793 internal volatile int m_completionCountdown = 1;
795 internal volatile List<Task> m_exceptionalChildren;
797 internal void SetCompleted()
799 m_completionEvent?.Set();
802 internal void DeregisterCancellationCallback()
804 if (m_cancellationRegistration !=
null)
808 m_cancellationRegistration.Value.Dispose();
810 catch (ObjectDisposedException)
813 m_cancellationRegistration =
null;
818 private sealed
class SetOnInvokeMres : ManualResetEventSlim, ITaskCompletionAction
820 internal SetOnInvokeMres()
821 : base(initialState: false, 0)
825 public void Invoke(Task completingTask)
831 private sealed
class SetOnCountdownMres : ManualResetEventSlim, ITaskCompletionAction
835 internal SetOnCountdownMres(
int count)
840 public void Invoke(Task completingTask)
842 if (Interlocked.Decrement(ref _count) == 0)
849 private sealed
class DelayPromise : Task<VoidTaskResult>
851 internal readonly CancellationToken Token;
853 internal CancellationTokenRegistration Registration;
855 internal Timer Timer;
857 internal DelayPromise(CancellationToken token)
860 if (AsyncCausalityTracer.LoggingOn)
862 AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, base.Id,
"Task.Delay", 0uL);
864 if (s_asyncDebuggingEnabled)
866 AddToActiveTasks(
this);
873 if (Token.IsCancellationRequested)
875 flag = TrySetCanceled(Token);
879 if (AsyncCausalityTracer.LoggingOn)
881 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required, base.Id, AsyncCausalityStatus.Completed);
883 if (s_asyncDebuggingEnabled)
885 RemoveFromActiveTasks(base.Id);
887 flag = TrySetResult(
default(VoidTaskResult));
895 Registration.Dispose();
900 private sealed
class WhenAllPromise : Task<VoidTaskResult>, ITaskCompletionAction
902 private readonly
Task[] m_tasks;
906 internal override bool ShouldNotifyDebuggerOfWaitCompletion
910 if (base.ShouldNotifyDebuggerOfWaitCompletion)
912 return AnyTaskRequiresNotifyDebuggerOfWaitCompletion(m_tasks);
918 internal WhenAllPromise(Task[] tasks)
920 if (AsyncCausalityTracer.LoggingOn)
922 AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, base.Id,
"Task.WhenAll", 0uL);
924 if (s_asyncDebuggingEnabled)
926 AddToActiveTasks(
this);
929 m_count = tasks.Length;
930 foreach (Task task
in tasks)
932 if (task.IsCompleted)
938 task.AddCompletionAction(
this);
943 public void Invoke(Task completedTask)
945 if (AsyncCausalityTracer.LoggingOn)
947 AsyncCausalityTracer.TraceOperationRelation(CausalityTraceLevel.Important, base.Id, CausalityRelation.Join);
949 if (Interlocked.Decrement(ref m_count) != 0)
955 for (
int i = 0; i < m_tasks.Length; i++)
957 Task task2 = m_tasks[i];
964 list.AddRange(task2.GetExceptionDispatchInfos());
966 else if (task2.IsCanceled && task ==
null)
970 if (task2.IsWaitNotificationEnabled)
972 SetNotificationForWaitCompletion(enabled:
true);
981 TrySetException(list);
986 TrySetCanceled(task.CancellationToken, task.GetCancellationExceptionDispatchInfo());
989 if (AsyncCausalityTracer.LoggingOn)
991 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required, base.Id, AsyncCausalityStatus.Completed);
993 if (s_asyncDebuggingEnabled)
995 RemoveFromActiveTasks(base.Id);
997 TrySetResult(
default(VoidTaskResult));
1001 private sealed
class WhenAllPromise<
T> : Task<T[]>, ITaskCompletionAction
1003 private readonly Task<T>[] m_tasks;
1005 private int m_count;
1007 internal override bool ShouldNotifyDebuggerOfWaitCompletion
1011 if (base.ShouldNotifyDebuggerOfWaitCompletion)
1013 return AnyTaskRequiresNotifyDebuggerOfWaitCompletion(m_tasks);
1019 internal WhenAllPromise(Task<T>[] tasks)
1022 m_count = tasks.Length;
1023 if (AsyncCausalityTracer.LoggingOn)
1025 AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required, base.Id,
"Task.WhenAll", 0uL);
1027 if (s_asyncDebuggingEnabled)
1029 AddToActiveTasks(
this);
1031 foreach (Task<T> task
in tasks)
1033 if (task.IsCompleted)
1039 task.AddCompletionAction(
this);
1044 public void Invoke(Task ignored)
1046 if (AsyncCausalityTracer.LoggingOn)
1048 AsyncCausalityTracer.TraceOperationRelation(CausalityTraceLevel.Important, base.Id, CausalityRelation.Join);
1050 if (Interlocked.Decrement(ref m_count) != 0)
1054 T[] array =
new T[m_tasks.Length];
1057 for (
int i = 0; i < m_tasks.Length; i++)
1059 Task<T> task2 = m_tasks[i];
1060 if (task2.IsFaulted)
1066 list.AddRange(task2.GetExceptionDispatchInfos());
1068 else if (task2.IsCanceled)
1077 array[i] = task2.GetResultCore(waitCompletionNotification:
false);
1079 if (task2.IsWaitNotificationEnabled)
1081 SetNotificationForWaitCompletion(enabled:
true);
1090 TrySetException(list);
1095 TrySetCanceled(task.CancellationToken, task.GetCancellationExceptionDispatchInfo());
1098 if (AsyncCausalityTracer.LoggingOn)
1100 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required, base.Id, AsyncCausalityStatus.Completed);
1102 if (s_asyncDebuggingEnabled)
1104 RemoveFromActiveTasks(base.Id);
1106 TrySetResult(array);
1111 internal static Task t_currentTask;
1114 private static StackGuard t_stackGuard;
1116 internal static int s_taskIdCounter;
1118 private static readonly TaskFactory s_factory =
new TaskFactory();
1120 private volatile int m_taskId;
1122 internal object m_action;
1124 internal object m_stateObject;
1126 internal TaskScheduler m_taskScheduler;
1128 internal readonly Task m_parent;
1130 internal volatile int m_stateFlags;
1132 private const int OptionsMask = 65535;
1134 internal const int TASK_STATE_STARTED = 65536;
1136 internal const int TASK_STATE_DELEGATE_INVOKED = 131072;
1138 internal const int TASK_STATE_DISPOSED = 262144;
1140 internal const int TASK_STATE_EXCEPTIONOBSERVEDBYPARENT = 524288;
1142 internal const int TASK_STATE_CANCELLATIONACKNOWLEDGED = 1048576;
1144 internal const int TASK_STATE_FAULTED = 2097152;
1146 internal const int TASK_STATE_CANCELED = 4194304;
1148 internal const int TASK_STATE_WAITING_ON_CHILDREN = 8388608;
1150 internal const int TASK_STATE_RAN_TO_COMPLETION = 16777216;
1152 internal const int TASK_STATE_WAITINGFORACTIVATION = 33554432;
1154 internal const int TASK_STATE_COMPLETION_RESERVED = 67108864;
1156 internal const int TASK_STATE_THREAD_WAS_ABORTED = 134217728;
1158 internal const int TASK_STATE_WAIT_COMPLETION_NOTIFICATION = 268435456;
1160 internal const int TASK_STATE_EXECUTIONCONTEXT_IS_NULL = 536870912;
1162 internal const int TASK_STATE_TASKSCHEDULED_WAS_FIRED = 1073741824;
1164 private const int TASK_STATE_COMPLETED_MASK = 23068672;
1166 private const int CANCELLATION_REQUESTED = 1;
1168 private volatile object m_continuationObject;
1170 private static readonly
object s_taskCompletionSentinel =
new object();
1172 [FriendAccessAllowed]
1173 internal static bool s_asyncDebuggingEnabled;
1177 private static readonly
object s_activeTasksLock =
new object();
1179 internal volatile ContingentProperties m_contingentProperties;
1181 private static readonly Action<object> s_taskCancelCallback = TaskCancelCallback;
1183 private static readonly Func<ContingentProperties> s_createContingentProperties = () =>
new ContingentProperties();
1185 private static Task s_completedTask;
1187 private static readonly Predicate<Task> s_IsExceptionObservedByParentPredicate = (Task t) => t.IsExceptionObservedByParent;
1192 private static readonly Predicate<object> s_IsTaskContinuationNullPredicate = (
object tc) => tc ==
null;
1194 private string DebuggerDisplayMethodDescription
1199 if ((
object)@delegate ==
null)
1203 return @delegate.Method.ToString();
1211 int stateFlags = m_stateFlags;
1212 return OptionsMethod(stateFlags);
1216 internal bool IsWaitNotificationEnabledOrNotRanToCompletion
1221 return (m_stateFlags & 0x11000000) != 16777216;
1225 internal virtual bool ShouldNotifyDebuggerOfWaitCompletion => IsWaitNotificationEnabled;
1227 internal bool IsWaitNotificationEnabled => (m_stateFlags & 0x10000000) != 0;
1231 [__DynamicallyInvokable]
1234 [__DynamicallyInvokable]
1239 int value = NewId();
1248 [__DynamicallyInvokable]
1251 [__DynamicallyInvokable]
1254 return InternalCurrent?.
Id;
1258 internal static Task InternalCurrent => t_currentTask;
1260 internal static StackGuard CurrentStackGuard
1264 StackGuard stackGuard = t_stackGuard;
1265 if (stackGuard ==
null)
1267 stackGuard = (t_stackGuard =
new StackGuard());
1275 [__DynamicallyInvokable]
1278 [__DynamicallyInvokable]
1284 result = GetExceptions(includeTaskCanceledExceptions:
false);
1292 [__DynamicallyInvokable]
1295 [__DynamicallyInvokable]
1298 int stateFlags = m_stateFlags;
1299 if ((stateFlags & 0x200000) != 0)
1303 if ((stateFlags & 0x400000) != 0)
1307 if ((stateFlags & 0x1000000) != 0)
1311 if ((stateFlags & 0x800000) != 0)
1313 return TaskStatus.WaitingForChildrenToComplete;
1315 if ((stateFlags & 0x20000) != 0)
1319 if ((stateFlags & 0x10000) != 0)
1323 if ((stateFlags & 0x2000000) != 0)
1334 [__DynamicallyInvokable]
1337 [__DynamicallyInvokable]
1340 return (m_stateFlags & 0x600000) == 4194304;
1344 internal bool IsCancellationRequested
1348 ContingentProperties contingentProperties = m_contingentProperties;
1349 if (contingentProperties !=
null)
1351 if (contingentProperties.m_internalCancellationRequested != 1)
1353 return contingentProperties.m_cancellationToken.IsCancellationRequested;
1361 internal CancellationToken CancellationToken => m_contingentProperties?.m_cancellationToken ??
default(CancellationToken);
1363 internal bool IsCancellationAcknowledged => (m_stateFlags & 0x100000) != 0;
1368 [__DynamicallyInvokable]
1371 [__DynamicallyInvokable]
1374 int stateFlags = m_stateFlags;
1375 return IsCompletedMethod(stateFlags);
1379 internal bool IsRanToCompletion => (m_stateFlags & 0x1600000) == 16777216;
1383 [__DynamicallyInvokable]
1386 [__DynamicallyInvokable]
1396 [__DynamicallyInvokable]
1399 [__DynamicallyInvokable]
1402 if ((m_stateFlags & 0x40000) != 0)
1412 [__DynamicallyInvokable]
1415 [__DynamicallyInvokable]
1418 return m_stateObject;
1425 [__DynamicallyInvokable]
1428 [__DynamicallyInvokable]
1435 internal TaskScheduler ExecutingTaskScheduler => m_taskScheduler;
1439 [__DynamicallyInvokable]
1440 public static TaskFactory
Factory 1442 [__DynamicallyInvokable]
1451 [__DynamicallyInvokable]
1454 [__DynamicallyInvokable]
1457 Task task = s_completedTask;
1470 ContingentProperties contingentProperties = EnsureContingentPropertiesInitialized(needsProtection:
true);
1471 if (contingentProperties.m_completionEvent ==
null)
1477 manualResetEventSlim.
Dispose();
1481 manualResetEventSlim.
Set();
1484 return contingentProperties.m_completionEvent;
1492 internal int ActiveChildCount
1496 ContingentProperties contingentProperties = m_contingentProperties;
1497 if (contingentProperties ==
null)
1501 return contingentProperties.m_completionCountdown - 1;
1505 internal bool ExceptionRecorded
1509 ContingentProperties contingentProperties = m_contingentProperties;
1510 if (contingentProperties !=
null && contingentProperties.m_exceptionsHolder !=
null)
1512 return contingentProperties.m_exceptionsHolder.ContainsFaultList;
1521 [__DynamicallyInvokable]
1524 [__DynamicallyInvokable]
1527 return (m_stateFlags & 0x200000) != 0;
1535 if ((m_stateFlags & 0x20000000) == 536870912)
1539 ContingentProperties contingentProperties = m_contingentProperties;
1540 if (contingentProperties !=
null && contingentProperties.m_capturedContext !=
null)
1542 return contingentProperties.m_capturedContext;
1544 return ExecutionContext.PreAllocatedDefault;
1550 m_stateFlags |= 536870912;
1552 else if (!value.IsPreAllocatedDefault)
1554 EnsureContingentPropertiesInitialized(needsProtection:
false).m_capturedContext = value;
1559 internal bool IsExceptionObservedByParent => (m_stateFlags & 0x80000) != 0;
1561 internal bool IsDelegateInvoked => (m_stateFlags & 0x20000) != 0;
1563 internal virtual object SavedStateForNextReplica
1574 internal virtual object SavedStateFromPreviousReplica
1585 internal virtual Task HandedOverChildReplica
1596 [FriendAccessAllowed]
1597 internal static bool AddToActiveTasks(Task task)
1599 lock (s_activeTasksLock)
1601 s_currentActiveTasks[task.Id] = task;
1606 [FriendAccessAllowed]
1607 internal static void RemoveFromActiveTasks(
int taskId)
1609 lock (s_activeTasksLock)
1611 s_currentActiveTasks.Remove(taskId);
1620 ContingentProperties contingentProperties = m_contingentProperties =
new ContingentProperties();
1621 contingentProperties.m_cancellationToken = ct;
1622 contingentProperties.m_internalCancellationRequested = 1;
1632 m_stateFlags = 33555456;
1639 throw new ArgumentOutOfRangeException(
"creationOptions");
1643 m_parent = InternalCurrent;
1645 TaskConstructorCore(
null, state,
default(CancellationToken), creationOptions, InternalTaskOptions.PromiseTask,
null);
1652 [__DynamicallyInvokable]
1656 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1657 PossiblyCaptureContext(ref stackMark);
1666 [__DynamicallyInvokable]
1670 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1671 PossiblyCaptureContext(ref stackMark);
1680 [__DynamicallyInvokable]
1682 : this(action, null, InternalCurrentIfAttached(creationOptions), default(
CancellationToken), creationOptions, InternalTaskOptions.
None, null)
1684 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1685 PossiblyCaptureContext(ref stackMark);
1696 [__DynamicallyInvokable]
1698 : this(action, null, InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.
None, null)
1700 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1701 PossiblyCaptureContext(ref stackMark);
1709 [__DynamicallyInvokable]
1710 public Task(Action<object> action,
object state)
1713 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1714 PossiblyCaptureContext(ref stackMark);
1724 [__DynamicallyInvokable]
1728 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1729 PossiblyCaptureContext(ref stackMark);
1739 [__DynamicallyInvokable]
1741 : this(action, state, InternalCurrentIfAttached(creationOptions), default(
CancellationToken), creationOptions, InternalTaskOptions.
None, null)
1743 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1744 PossiblyCaptureContext(ref stackMark);
1756 [__DynamicallyInvokable]
1758 : this(action, state, InternalCurrentIfAttached(creationOptions), cancellationToken, creationOptions, InternalTaskOptions.
None, null)
1760 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
1761 PossiblyCaptureContext(ref stackMark);
1765 : this(action, state, parent, cancellationToken, creationOptions, internalOptions, scheduler)
1767 PossiblyCaptureContext(ref stackMark);
1772 if ((
object)action ==
null)
1776 if ((creationOptions &
TaskCreationOptions.AttachedToParent) != 0 || (internalOptions & InternalTaskOptions.SelfReplicating) != 0)
1780 TaskConstructorCore(action, state, cancellationToken, creationOptions, internalOptions, scheduler);
1783 internal void TaskConstructorCore(
object action,
object state, CancellationToken cancellationToken,
TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
1786 m_stateObject = state;
1787 m_taskScheduler = scheduler;
1790 throw new ArgumentOutOfRangeException(
"creationOptions");
1792 if ((creationOptions &
TaskCreationOptions.LongRunning) != 0 && (internalOptions & InternalTaskOptions.SelfReplicating) != 0)
1794 throw new InvalidOperationException(Environment.GetResourceString(
"Task_ctor_LRandSR"));
1796 int num = (int)creationOptions | (
int)internalOptions;
1797 if (m_action ==
null || (internalOptions & InternalTaskOptions.ContinuationTask) != 0)
1804 m_parent.AddNewChild();
1806 if (cancellationToken.CanBeCanceled)
1808 AssignCancellationToken(cancellationToken,
null,
null);
1812 private void AssignCancellationToken(CancellationToken cancellationToken, Task antecedent, TaskContinuation continuation)
1814 ContingentProperties contingentProperties = EnsureContingentPropertiesInitialized(needsProtection:
false);
1815 contingentProperties.m_cancellationToken = cancellationToken;
1818 if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource)
1820 cancellationToken.ThrowIfSourceDisposed();
1824 if (cancellationToken.IsCancellationRequested)
1826 InternalCancel(bCancelNonExecutingOnly:
false);
1830 CancellationTokenRegistration value = (antecedent !=
null) ? cancellationToken.InternalRegisterWithoutEC(s_taskCancelCallback,
new Tuple<Task, Task, TaskContinuation>(
this, antecedent, continuation)) : cancellationToken.InternalRegisterWithoutEC(s_taskCancelCallback,
this);
1831 contingentProperties.m_cancellationRegistration =
new Shared<CancellationTokenRegistration>(value);
1839 m_parent.DisregardChild();
1845 private static void TaskCancelCallback(
object o)
1847 Task task = o as Task;
1850 Tuple<Task, Task, TaskContinuation> tuple = o as Tuple<Task, Task, TaskContinuation>;
1854 Task item = tuple.Item2;
1855 TaskContinuation item2 = tuple.Item3;
1856 item.RemoveContinuation(item2);
1859 task.InternalCancel(bCancelNonExecutingOnly:
false);
1862 [SecuritySafeCritical]
1863 internal void PossiblyCaptureContext(ref StackCrawlMark stackMark)
1865 CapturedContext = ExecutionContext.
Capture(ref stackMark, ExecutionContext.CaptureOptions.IgnoreSyncCtx | ExecutionContext.CaptureOptions.OptimizeDefaultCase);
1873 internal bool AtomicStateUpdate(
int newBits,
int illegalBits)
1875 SpinWait spinWait =
default(SpinWait);
1878 int stateFlags = m_stateFlags;
1879 if ((stateFlags & illegalBits) != 0)
1883 if (Interlocked.CompareExchange(ref m_stateFlags, stateFlags | newBits, stateFlags) == stateFlags)
1887 spinWait.SpinOnce();
1892 internal bool AtomicStateUpdate(
int newBits,
int illegalBits, ref
int oldFlags)
1894 SpinWait spinWait =
default(SpinWait);
1897 oldFlags = m_stateFlags;
1898 if ((oldFlags & illegalBits) != 0)
1902 if (Interlocked.CompareExchange(ref m_stateFlags, oldFlags | newBits, oldFlags) == oldFlags)
1906 spinWait.SpinOnce();
1911 internal void SetNotificationForWaitCompletion(
bool enabled)
1915 bool flag = AtomicStateUpdate(268435456, 90177536);
1918 SpinWait spinWait =
default(SpinWait);
1921 int stateFlags = m_stateFlags;
1922 int value = stateFlags & -268435457;
1923 if (Interlocked.CompareExchange(ref m_stateFlags, value, stateFlags) != stateFlags)
1925 spinWait.SpinOnce();
1932 internal bool NotifyDebuggerOfWaitCompletionIfNecessary()
1934 if (IsWaitNotificationEnabled && ShouldNotifyDebuggerOfWaitCompletion)
1936 NotifyDebuggerOfWaitCompletion();
1942 internal static bool AnyTaskRequiresNotifyDebuggerOfWaitCompletion(Task[] tasks)
1944 foreach (Task task
in tasks)
1946 if (task !=
null && task.IsWaitNotificationEnabled && task.ShouldNotifyDebuggerOfWaitCompletion)
1955 private void NotifyDebuggerOfWaitCompletion()
1957 SetNotificationForWaitCompletion(enabled:
false);
1960 internal bool MarkStarted()
1962 return AtomicStateUpdate(65536, 4259840);
1966 internal bool FireTaskScheduledIfNeeded(TaskScheduler ts)
1968 TplEtwProvider log = TplEtwProvider.Log;
1969 if (log.IsEnabled() && (m_stateFlags & 0x40000000) == 0)
1971 m_stateFlags |= 1073741824;
1972 Task internalCurrent = InternalCurrent;
1973 Task parent = m_parent;
1974 log.TaskScheduled(ts.Id, internalCurrent?.Id ?? 0,
Id, parent?.Id ?? 0, (
int)Options, Thread.GetDomainID());
1980 internal void AddNewChild()
1982 ContingentProperties contingentProperties = EnsureContingentPropertiesInitialized(needsProtection:
true);
1983 if (contingentProperties.m_completionCountdown == 1 && !IsSelfReplicatingRoot)
1985 contingentProperties.m_completionCountdown++;
1989 Interlocked.Increment(ref contingentProperties.m_completionCountdown);
1993 internal void DisregardChild()
1995 ContingentProperties contingentProperties = EnsureContingentPropertiesInitialized(needsProtection:
true);
1996 Interlocked.Decrement(ref contingentProperties.m_completionCountdown);
2002 [__DynamicallyInvokable]
2014 [__DynamicallyInvokable]
2017 int stateFlags = m_stateFlags;
2018 if (IsCompletedMethod(stateFlags))
2022 if (scheduler ==
null)
2039 ScheduleAndStart(needsProtection:
true);
2045 [__DynamicallyInvokable]
2056 [__DynamicallyInvokable]
2059 if (scheduler ==
null)
2063 InternalRunSynchronously(scheduler, waitForCompletion:
true);
2066 [SecuritySafeCritical]
2067 internal void InternalRunSynchronously(
TaskScheduler scheduler,
bool waitForCompletion)
2069 int stateFlags = m_stateFlags;
2079 if (IsCompletedMethod(stateFlags))
2083 if (Interlocked.CompareExchange(ref m_taskScheduler, scheduler,
null) !=
null)
2085 throw new InvalidOperationException(Environment.GetResourceString(
"Task_RunSynchronously_AlreadyStarted"));
2092 if (!scheduler.TryRunInline(
this, taskWasPreviouslyQueued:
false))
2094 scheduler.InternalQueueTask(
this);
2099 SpinThenBlockingWait(-1,
default(CancellationToken));
2104 if (!flag && !(ex is ThreadAbortException))
2106 TaskSchedulerException ex2 =
new TaskSchedulerException(ex);
2108 Finish(bUserDelegateExecuted:
false);
2109 m_contingentProperties.m_exceptionsHolder.MarkAsHandled(calledFromFinalizer:
false);
2116 throw new InvalidOperationException(Environment.GetResourceString(
"Task_RunSynchronously_TaskCompleted"));
2119 internal static Task InternalStartNew(Task creatingTask, Delegate action,
object state, CancellationToken cancellationToken, TaskScheduler scheduler,
TaskCreationOptions options, InternalTaskOptions internalOptions, ref StackCrawlMark stackMark)
2121 if (scheduler ==
null)
2123 throw new ArgumentNullException(
"scheduler");
2125 Task task =
new Task(action, state, creatingTask, cancellationToken, options, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler);
2126 task.PossiblyCaptureContext(ref stackMark);
2127 task.ScheduleAndStart(needsProtection:
false);
2131 internal static int NewId()
2136 num = Interlocked.Increment(ref s_taskIdCounter);
2139 TplEtwProvider.Log.NewID(num);
2149 return InternalCurrent;
2152 internal ContingentProperties EnsureContingentPropertiesInitialized(
bool needsProtection)
2154 ContingentProperties contingentProperties = m_contingentProperties;
2155 if (contingentProperties ==
null)
2157 return EnsureContingentPropertiesInitializedCore(needsProtection);
2159 return contingentProperties;
2162 private ContingentProperties EnsureContingentPropertiesInitializedCore(
bool needsProtection)
2164 if (needsProtection)
2166 return LazyInitializer.EnsureInitialized(ref m_contingentProperties, s_createContingentProperties);
2168 return m_contingentProperties =
new ContingentProperties();
2171 private static bool IsCompletedMethod(
int flags)
2173 return (flags & 0x1600000) != 0;
2176 private static ExecutionContext CopyExecutionContext(ExecutionContext capturedContext)
2178 if (capturedContext ==
null)
2182 if (capturedContext.IsPreAllocatedDefault)
2184 return ExecutionContext.PreAllocatedDefault;
2186 return capturedContext.CreateCopy();
2212 ContingentProperties contingentProperties = m_contingentProperties;
2213 if (contingentProperties !=
null)
2216 if (completionEvent !=
null)
2218 contingentProperties.m_completionEvent =
null;
2219 if (!completionEvent.
IsSet)
2221 completionEvent.
Set();
2227 m_stateFlags |= 262144;
2230 [SecuritySafeCritical]
2231 internal void ScheduleAndStart(
bool needsProtection)
2233 if (needsProtection)
2242 m_stateFlags |= 65536;
2244 if (s_asyncDebuggingEnabled)
2246 AddToActiveTasks(
this);
2250 AsyncCausalityTracer.TraceOperationCreation(CausalityTraceLevel.Required,
Id,
"Task: " + ((Delegate)m_action).Method.Name, 0uL);
2254 m_taskScheduler.InternalQueueTask(
this);
2256 catch (ThreadAbortException exceptionObject)
2258 AddException(exceptionObject);
2259 FinishThreadAbortedTask(bTAEAddedToExceptionHolder:
true, delegateRan:
false);
2263 TaskSchedulerException ex =
new TaskSchedulerException(innerException);
2265 Finish(bUserDelegateExecuted:
false);
2268 m_contingentProperties.m_exceptionsHolder.MarkAsHandled(calledFromFinalizer:
false);
2274 internal void AddException(
object exceptionObject)
2276 AddException(exceptionObject, representsCancellation:
false);
2279 internal void AddException(
object exceptionObject,
bool representsCancellation)
2281 ContingentProperties contingentProperties = EnsureContingentPropertiesInitialized(needsProtection:
true);
2282 if (contingentProperties.m_exceptionsHolder ==
null)
2284 TaskExceptionHolder taskExceptionHolder =
new TaskExceptionHolder(
this);
2285 if (Interlocked.CompareExchange(ref contingentProperties.m_exceptionsHolder, taskExceptionHolder,
null) !=
null)
2287 taskExceptionHolder.MarkAsHandled(calledFromFinalizer:
false);
2290 lock (contingentProperties)
2292 contingentProperties.m_exceptionsHolder.Add(exceptionObject, representsCancellation);
2296 private AggregateException GetExceptions(
bool includeTaskCanceledExceptions)
2299 if (includeTaskCanceledExceptions &&
IsCanceled)
2301 ex =
new TaskCanceledException(
this);
2303 if (ExceptionRecorded)
2305 return m_contingentProperties.m_exceptionsHolder.CreateExceptionObject(calledFromFinalizer:
false, ex);
2309 return new AggregateException(ex);
2320 return m_contingentProperties.m_exceptionsHolder.GetExceptionDispatchInfos();
2325 ContingentProperties contingentProperties = m_contingentProperties;
2326 if (contingentProperties ==
null)
2330 return contingentProperties.m_exceptionsHolder?.GetCancellationExceptionDispatchInfo();
2333 internal void ThrowIfExceptional(
bool includeTaskCanceledExceptions)
2335 Exception exceptions = GetExceptions(includeTaskCanceledExceptions);
2336 if (exceptions !=
null)
2338 UpdateExceptionObservedStatus();
2343 internal void UpdateExceptionObservedStatus()
2347 m_stateFlags |= 524288;
2351 internal void Finish(
bool bUserDelegateExecuted)
2353 if (!bUserDelegateExecuted)
2358 ContingentProperties contingentProperties = m_contingentProperties;
2359 if (contingentProperties ==
null || (contingentProperties.m_completionCountdown == 1 && !IsSelfReplicatingRoot) || Interlocked.Decrement(ref contingentProperties.m_completionCountdown) == 0)
2365 AtomicStateUpdate(8388608, 23068672);
2367 List<Task> list = (contingentProperties !=
null) ? contingentProperties.m_exceptionalChildren :
null;
2372 list.RemoveAll(s_IsExceptionObservedByParentPredicate);
2377 internal void FinishStageTwo()
2379 AddExceptionsFromChildren();
2381 if (ExceptionRecorded)
2384 if (AsyncCausalityTracer.LoggingOn)
2386 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required,
Id, AsyncCausalityStatus.Error);
2388 if (s_asyncDebuggingEnabled)
2390 RemoveFromActiveTasks(
Id);
2393 else if (IsCancellationRequested && IsCancellationAcknowledged)
2396 if (AsyncCausalityTracer.LoggingOn)
2398 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required,
Id, AsyncCausalityStatus.Canceled);
2400 if (s_asyncDebuggingEnabled)
2402 RemoveFromActiveTasks(
Id);
2408 if (AsyncCausalityTracer.LoggingOn)
2410 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required,
Id, AsyncCausalityStatus.Completed);
2412 if (s_asyncDebuggingEnabled)
2414 RemoveFromActiveTasks(
Id);
2417 Interlocked.Exchange(ref m_stateFlags, m_stateFlags | num);
2418 ContingentProperties contingentProperties = m_contingentProperties;
2419 if (contingentProperties !=
null)
2421 contingentProperties.SetCompleted();
2422 contingentProperties.DeregisterCancellationCallback();
2427 internal void FinishStageThree()
2432 m_parent.ProcessChildCompletion(
this);
2434 FinishContinuations();
2437 internal void ProcessChildCompletion(Task childTask)
2439 ContingentProperties contingentProperties = m_contingentProperties;
2440 if (childTask.IsFaulted && !childTask.IsExceptionObservedByParent)
2442 if (contingentProperties.m_exceptionalChildren ==
null)
2444 Interlocked.CompareExchange(ref contingentProperties.m_exceptionalChildren,
new List<Task>(),
null);
2446 List<Task> exceptionalChildren = contingentProperties.m_exceptionalChildren;
2447 if (exceptionalChildren !=
null)
2449 lock (exceptionalChildren)
2451 exceptionalChildren.
Add(childTask);
2455 if (Interlocked.Decrement(ref contingentProperties.m_completionCountdown) == 0)
2461 internal void AddExceptionsFromChildren()
2463 ContingentProperties contingentProperties = m_contingentProperties;
2464 List<Task> list = (contingentProperties !=
null) ? contingentProperties.m_exceptionalChildren :
null;
2469 foreach (Task item
in list)
2471 if (item.IsFaulted && !item.IsExceptionObservedByParent)
2473 TaskExceptionHolder exceptionsHolder = item.m_contingentProperties.m_exceptionsHolder;
2474 AddException(exceptionsHolder.CreateExceptionObject(calledFromFinalizer:
false,
null));
2478 contingentProperties.m_exceptionalChildren =
null;
2482 internal void FinishThreadAbortedTask(
bool bTAEAddedToExceptionHolder,
bool delegateRan)
2484 if (bTAEAddedToExceptionHolder)
2486 m_contingentProperties.m_exceptionsHolder.MarkAsHandled(calledFromFinalizer:
false);
2488 if (AtomicStateUpdate(134217728, 157286400))
2490 Finish(delegateRan);
2494 private void Execute()
2496 if (IsSelfReplicatingRoot)
2498 ExecuteSelfReplicating(
this);
2506 catch (ThreadAbortException unhandledException)
2508 if (!IsChildReplica)
2510 HandleException(unhandledException);
2511 FinishThreadAbortedTask(bTAEAddedToExceptionHolder:
true, delegateRan:
true);
2516 HandleException(unhandledException2);
2521 internal virtual bool ShouldReplicate()
2526 internal virtual Task CreateReplicaTask(Action<object> taskReplicaDelegate,
object stateObject, Task parentTask, TaskScheduler taskScheduler,
TaskCreationOptions creationOptionsForReplica, InternalTaskOptions internalOptionsForReplica)
2528 return new Task(taskReplicaDelegate, stateObject, parentTask,
default(CancellationToken), creationOptionsForReplica, internalOptionsForReplica, parentTask.ExecutingTaskScheduler);
2531 private static void ExecuteSelfReplicating(Task root)
2534 InternalTaskOptions internalOptionsForReplicas = InternalTaskOptions.ChildReplica | InternalTaskOptions.SelfReplicating | InternalTaskOptions.QueuedByRuntime;
2535 bool replicasAreQuitting =
false;
2536 Action<object> taskReplicaDelegate =
null;
2537 taskReplicaDelegate = delegate
2539 Task internalCurrent = InternalCurrent;
2540 Task task = internalCurrent.HandedOverChildReplica;
2543 if (!root.ShouldReplicate() || Volatile.Read(ref replicasAreQuitting))
2547 ExecutionContext capturedContext = root.CapturedContext;
2548 task = root.CreateReplicaTask(taskReplicaDelegate, root.m_stateObject, root, root.ExecutingTaskScheduler, creationOptionsForReplicas, internalOptionsForReplicas);
2549 task.CapturedContext = CopyExecutionContext(capturedContext);
2550 task.ScheduleAndStart(needsProtection:
false);
2554 root.InnerInvokeWithArg(internalCurrent);
2558 root.HandleException(ex);
2559 if (ex is ThreadAbortException)
2561 internalCurrent.FinishThreadAbortedTask(bTAEAddedToExceptionHolder:
false, delegateRan:
true);
2564 object savedStateForNextReplica = internalCurrent.SavedStateForNextReplica;
2565 if (savedStateForNextReplica !=
null)
2567 Task task2 = root.CreateReplicaTask(taskReplicaDelegate, root.m_stateObject, root, root.ExecutingTaskScheduler, creationOptionsForReplicas, internalOptionsForReplicas);
2568 ExecutionContext capturedContext2 = root.CapturedContext;
2569 task2.CapturedContext = CopyExecutionContext(capturedContext2);
2570 task2.HandedOverChildReplica = task;
2571 task2.SavedStateFromPreviousReplica = savedStateForNextReplica;
2572 task2.ScheduleAndStart(needsProtection:
false);
2576 replicasAreQuitting =
true;
2579 task.InternalCancel(bCancelNonExecutingOnly:
true);
2583 root.HandleException(unhandledException);
2587 taskReplicaDelegate(
null);
2591 void IThreadPoolWorkItem.ExecuteWorkItem()
2593 ExecuteEntry(bPreventDoubleExecution:
false);
2597 void IThreadPoolWorkItem.MarkAborted(ThreadAbortException tae)
2601 HandleException(tae);
2602 FinishThreadAbortedTask(bTAEAddedToExceptionHolder:
true, delegateRan:
false);
2606 [SecuritySafeCritical]
2607 internal bool ExecuteEntry(
bool bPreventDoubleExecution)
2612 if (!AtomicStateUpdate(131072, 23199744, ref oldFlags) && (oldFlags & 0x400000) == 0)
2619 m_stateFlags |= 131072;
2623 ExecuteWithThreadLocal(ref t_currentTask);
2627 int num = Interlocked.Exchange(ref m_stateFlags, m_stateFlags | 0x400000);
2628 if ((num & 0x400000) == 0)
2630 CancellationCleanupLogic();
2637 private void ExecuteWithThreadLocal(ref Task currentTaskSlot)
2639 Task task = currentTaskSlot;
2640 TplEtwProvider log = TplEtwProvider.Log;
2641 Guid oldActivityThatWillContinue =
default(Guid);
2642 bool flag = log.IsEnabled();
2645 if (log.TasksSetActivityIds)
2651 log.TaskStarted(task.m_taskScheduler.Id, task.Id,
Id);
2655 log.TaskStarted(TaskScheduler.Current.Id, 0,
Id);
2658 if (AsyncCausalityTracer.LoggingOn)
2660 AsyncCausalityTracer.TraceSynchronousWorkStart(CausalityTraceLevel.Required,
Id, CausalitySynchronousWork.Execution);
2664 currentTaskSlot =
this;
2665 ExecutionContext capturedContext = CapturedContext;
2666 if (capturedContext ==
null)
2672 if (IsSelfReplicatingRoot || IsChildReplica)
2674 CapturedContext = CopyExecutionContext(capturedContext);
2677 ExecutionContext.Run(capturedContext, callback,
this, preserveSyncCtx:
true);
2679 if (AsyncCausalityTracer.LoggingOn)
2681 AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalityTraceLevel.Required, CausalitySynchronousWork.Execution);
2683 Finish(bUserDelegateExecuted:
true);
2687 currentTaskSlot = task;
2692 log.TaskCompleted(task.m_taskScheduler.Id, task.Id,
Id,
IsFaulted);
2696 log.TaskCompleted(TaskScheduler.Current.Id, 0,
Id,
IsFaulted);
2698 if (log.TasksSetActivityIds)
2707 private static void ExecutionContextCallback(
object obj)
2709 Task task = obj as Task;
2713 internal virtual void InnerInvoke()
2722 (m_action as Action<object>)?.
Invoke(m_stateObject);
2727 internal void InnerInvokeWithArg(Task childTask)
2732 private void HandleException(
Exception unhandledException)
2734 OperationCanceledException ex = unhandledException as OperationCanceledException;
2735 if (ex !=
null && IsCancellationRequested && m_contingentProperties.m_cancellationToken == ex.CancellationToken)
2737 SetCancellationAcknowledged();
2738 AddException(ex, representsCancellation:
true);
2742 AddException(unhandledException);
2748 [__DynamicallyInvokable]
2758 [__DynamicallyInvokable]
2765 internal void SetContinuationForAwait(
Action continuationAction,
bool continueOnCapturedContext,
bool flowExecutionContext, ref StackCrawlMark stackMark)
2767 TaskContinuation taskContinuation =
null;
2768 if (continueOnCapturedContext)
2773 taskContinuation =
new SynchronizationContextAwaitTaskContinuation(currentNoFlow, continuationAction, flowExecutionContext, ref stackMark);
2777 TaskScheduler internalCurrent = TaskScheduler.InternalCurrent;
2778 if (internalCurrent !=
null && internalCurrent != TaskScheduler.Default)
2780 taskContinuation =
new TaskSchedulerAwaitTaskContinuation(internalCurrent, continuationAction, flowExecutionContext, ref stackMark);
2784 if (taskContinuation ==
null && flowExecutionContext)
2786 taskContinuation =
new AwaitTaskContinuation(continuationAction, flowExecutionContext:
true, ref stackMark);
2788 if (taskContinuation !=
null)
2790 if (!AddTaskContinuation(taskContinuation, addBeforeOthers:
false))
2792 taskContinuation.Run(
this, bCanInlineContinuationTask:
false);
2795 else if (!AddTaskContinuation(continuationAction, addBeforeOthers:
false))
2797 AwaitTaskContinuation.UnsafeScheduleAction(continuationAction,
this);
2803 [__DynamicallyInvokable]
2812 [__DynamicallyInvokable]
2827 [__DynamicallyInvokable]
2831 if (num < -1 || num >
int.MaxValue)
2843 [__DynamicallyInvokable]
2846 Wait(-1, cancellationToken);
2857 [__DynamicallyInvokable]
2858 public bool Wait(
int millisecondsTimeout)
2873 [__DynamicallyInvokable]
2876 if (millisecondsTimeout < -1)
2880 if (!IsWaitNotificationEnabledOrNotRanToCompletion)
2884 if (!InternalWait(millisecondsTimeout, cancellationToken))
2888 if (IsWaitNotificationEnabledOrNotRanToCompletion)
2890 NotifyDebuggerOfWaitCompletionIfNecessary();
2895 ThrowIfExceptional(includeTaskCanceledExceptions:
true);
2900 private bool WrappedTryRunInline()
2902 if (m_taskScheduler ==
null)
2908 return m_taskScheduler.TryRunInline(
this, taskWasPreviouslyQueued:
true);
2912 if (!(ex is ThreadAbortException))
2914 TaskSchedulerException ex2 =
new TaskSchedulerException(ex);
2922 internal bool InternalWait(
int millisecondsTimeout, CancellationToken cancellationToken)
2924 TplEtwProvider log = TplEtwProvider.Log;
2925 bool flag = log.IsEnabled();
2928 Task internalCurrent = InternalCurrent;
2929 log.TaskWaitBegin(internalCurrent?.m_taskScheduler.Id ?? TaskScheduler.Default.Id, internalCurrent?.Id ?? 0,
Id, TplEtwProvider.TaskWaitBehavior.Synchronous, 0, Thread.GetDomainID());
2935 flag2 = ((millisecondsTimeout == -1 && !cancellationToken.CanBeCanceled && WrappedTryRunInline() &&
IsCompleted) || SpinThenBlockingWait(millisecondsTimeout, cancellationToken));
2939 Task internalCurrent2 = InternalCurrent;
2940 if (internalCurrent2 !=
null)
2942 log.TaskWaitEnd(internalCurrent2.m_taskScheduler.Id, internalCurrent2.Id,
Id);
2946 log.TaskWaitEnd(TaskScheduler.Default.Id, 0,
Id);
2948 log.TaskWaitContinuationComplete(
Id);
2953 private bool SpinThenBlockingWait(
int millisecondsTimeout, CancellationToken cancellationToken)
2955 bool flag = millisecondsTimeout == -1;
2956 uint num = (uint)((!flag) ? Environment.TickCount : 0);
2957 bool flag2 = SpinWait(millisecondsTimeout);
2960 SetOnInvokeMres setOnInvokeMres =
new SetOnInvokeMres();
2963 AddCompletionAction(setOnInvokeMres, addBeforeOthers:
true);
2966 return setOnInvokeMres.Wait(-1, cancellationToken);
2968 uint num2 = (uint)(Environment.TickCount - (
int)num);
2969 if (num2 < millisecondsTimeout)
2971 return setOnInvokeMres.Wait((
int)(millisecondsTimeout - num2), cancellationToken);
2979 RemoveContinuation(setOnInvokeMres);
2986 private bool SpinWait(
int millisecondsTimeout)
2992 if (millisecondsTimeout == 0)
2996 int num = PlatformHelper.IsSingleProcessor ? 1 : 10;
2997 for (
int i = 0; i < num; i++)
3009 Thread.SpinWait(PlatformHelper.ProcessorCount * (4 << i));
3015 [SecuritySafeCritical]
3016 internal bool InternalCancel(
bool bCancelNonExecutingOnly)
3020 TaskSchedulerException ex =
null;
3021 if ((m_stateFlags & 0x10000) != 0)
3023 TaskScheduler taskScheduler = m_taskScheduler;
3026 flag = (taskScheduler?.TryDequeue(
this) ??
false);
3030 if (!(ex2 is ThreadAbortException))
3032 ex =
new TaskSchedulerException(ex2);
3036 if ((!flag && bCancelNonExecutingOnly) & flag3)
3038 flag2 = AtomicStateUpdate(4194304, 4325376);
3041 if (!bCancelNonExecutingOnly | flag | flag2)
3043 RecordInternalCancellationRequest();
3046 flag2 = AtomicStateUpdate(4194304, 4325376);
3048 else if (!flag2 && (m_stateFlags & 0x10000) == 0)
3050 flag2 = AtomicStateUpdate(4194304, 23265280);
3054 CancellationCleanupLogic();
3064 internal void RecordInternalCancellationRequest()
3066 ContingentProperties contingentProperties = EnsureContingentPropertiesInitialized(needsProtection:
true);
3067 contingentProperties.m_internalCancellationRequested = 1;
3070 internal void RecordInternalCancellationRequest(CancellationToken tokenToRecord)
3072 RecordInternalCancellationRequest();
3073 if (tokenToRecord !=
default(CancellationToken))
3075 m_contingentProperties.m_cancellationToken = tokenToRecord;
3079 internal void RecordInternalCancellationRequest(CancellationToken tokenToRecord,
object cancellationException)
3081 RecordInternalCancellationRequest(tokenToRecord);
3082 if (cancellationException !=
null)
3084 AddException(cancellationException, representsCancellation:
true);
3088 internal void CancellationCleanupLogic()
3090 Interlocked.Exchange(ref m_stateFlags, m_stateFlags | 0x400000);
3091 ContingentProperties contingentProperties = m_contingentProperties;
3092 if (contingentProperties !=
null)
3094 contingentProperties.SetCompleted();
3095 contingentProperties.DeregisterCancellationCallback();
3097 if (AsyncCausalityTracer.LoggingOn)
3099 AsyncCausalityTracer.TraceOperationCompletion(CausalityTraceLevel.Required,
Id, AsyncCausalityStatus.Canceled);
3101 if (s_asyncDebuggingEnabled)
3103 RemoveFromActiveTasks(
Id);
3108 private void SetCancellationAcknowledged()
3110 m_stateFlags |= 1048576;
3113 [SecuritySafeCritical]
3114 internal void FinishContinuations()
3116 object obj = Interlocked.Exchange(ref m_continuationObject, s_taskCompletionSentinel);
3117 TplEtwProvider.Log.RunningContinuation(
Id, obj);
3122 if (AsyncCausalityTracer.LoggingOn)
3124 AsyncCausalityTracer.TraceSynchronousWorkStart(CausalityTraceLevel.Required,
Id, CausalitySynchronousWork.CompletionNotification);
3126 bool flag = (m_stateFlags & 0x8000000) == 0 && Thread.CurrentThread.ThreadState !=
ThreadState.AbortRequested && (m_stateFlags & 0x40) == 0;
3130 AwaitTaskContinuation.RunOrScheduleAction(action, flag, ref t_currentTask);
3131 LogFinishCompletionNotification();
3134 ITaskCompletionAction taskCompletionAction = obj as ITaskCompletionAction;
3135 if (taskCompletionAction !=
null)
3139 taskCompletionAction.Invoke(
this);
3143 ThreadPool.UnsafeQueueCustomWorkItem(
new CompletionActionInvoker(taskCompletionAction,
this), forceGlobal:
false);
3145 LogFinishCompletionNotification();
3148 TaskContinuation taskContinuation = obj as TaskContinuation;
3149 if (taskContinuation !=
null)
3151 taskContinuation.Run(
this, flag);
3152 LogFinishCompletionNotification();
3158 LogFinishCompletionNotification();
3164 int count = list.Count;
3165 for (
int i = 0; i < count; i++)
3167 StandardTaskContinuation standardTaskContinuation = list[i] as StandardTaskContinuation;
3170 TplEtwProvider.Log.RunningContinuationList(
Id, i, standardTaskContinuation);
3172 standardTaskContinuation.Run(
this, flag);
3175 for (
int j = 0; j < count; j++)
3177 object obj2 = list[j];
3183 TplEtwProvider.Log.RunningContinuationList(
Id, j, obj2);
3185 if (action2 !=
null)
3187 AwaitTaskContinuation.RunOrScheduleAction(action2, flag, ref t_currentTask);
3190 TaskContinuation taskContinuation2 = obj2 as TaskContinuation;
3191 if (taskContinuation2 !=
null)
3193 taskContinuation2.Run(
this, flag);
3196 ITaskCompletionAction taskCompletionAction2 = (ITaskCompletionAction)obj2;
3199 taskCompletionAction2.Invoke(
this);
3203 ThreadPool.UnsafeQueueCustomWorkItem(
new CompletionActionInvoker(taskCompletionAction2,
this), forceGlobal:
false);
3206 LogFinishCompletionNotification();
3209 private void LogFinishCompletionNotification()
3211 if (AsyncCausalityTracer.LoggingOn)
3213 AsyncCausalityTracer.TraceSynchronousWorkCompletion(CausalityTraceLevel.Required, CausalitySynchronousWork.CompletionNotification);
3222 [__DynamicallyInvokable]
3225 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3236 [__DynamicallyInvokable]
3239 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3250 [__DynamicallyInvokable]
3253 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3264 [__DynamicallyInvokable]
3267 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3281 [__DynamicallyInvokable]
3284 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3285 return ContinueWith(continuationAction, scheduler, cancellationToken, continuationOptions, ref stackMark);
3290 if (continuationAction ==
null)
3294 if (scheduler ==
null)
3298 CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
3299 Task task =
new ContinuationTaskFromTask(
this, continuationAction,
null, creationOptions, internalOptions, ref stackMark);
3300 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
3310 [__DynamicallyInvokable]
3313 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3325 [__DynamicallyInvokable]
3328 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3340 [__DynamicallyInvokable]
3343 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3355 [__DynamicallyInvokable]
3358 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3374 [__DynamicallyInvokable]
3377 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3378 return ContinueWith(continuationAction, state, scheduler, cancellationToken, continuationOptions, ref stackMark);
3383 if (continuationAction ==
null)
3387 if (scheduler ==
null)
3391 CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
3392 Task task =
new ContinuationTaskFromTask(
this, continuationAction, state, creationOptions, internalOptions, ref stackMark);
3393 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
3404 [__DynamicallyInvokable]
3407 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3419 [__DynamicallyInvokable]
3422 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3434 [__DynamicallyInvokable]
3437 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3450 [__DynamicallyInvokable]
3453 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3468 [__DynamicallyInvokable]
3471 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3472 return ContinueWith(continuationFunction, scheduler, cancellationToken, continuationOptions, ref stackMark);
3477 if (continuationFunction ==
null)
3481 if (scheduler ==
null)
3485 CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
3486 Task<TResult> task =
new ContinuationResultTaskFromTask<TResult>(
this, continuationFunction,
null, creationOptions, internalOptions, ref stackMark);
3487 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
3498 [__DynamicallyInvokable]
3501 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3514 [__DynamicallyInvokable]
3517 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3530 [__DynamicallyInvokable]
3533 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3546 [__DynamicallyInvokable]
3549 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3566 [__DynamicallyInvokable]
3569 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
3570 return ContinueWith(continuationFunction, state, scheduler, cancellationToken, continuationOptions, ref stackMark);
3575 if (continuationFunction ==
null)
3579 if (scheduler ==
null)
3583 CreationOptionsFromContinuationOptions(continuationOptions, out
TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions);
3584 Task<TResult> task =
new ContinuationResultTaskFromTask<TResult>(
this, continuationFunction, state, creationOptions, internalOptions, ref stackMark);
3585 ContinueWithCore(task, scheduler, cancellationToken, continuationOptions);
3594 if ((continuationOptions & taskContinuationOptions3) == taskContinuationOptions3)
3596 throw new ArgumentOutOfRangeException(
"continuationOptions", Environment.GetResourceString(
"Task_ContinueWith_ESandLR"));
3600 throw new ArgumentOutOfRangeException(
"continuationOptions");
3602 if ((continuationOptions & taskContinuationOptions) == taskContinuationOptions)
3604 throw new ArgumentOutOfRangeException(
"continuationOptions", Environment.GetResourceString(
"Task_ContinueWith_NotOnAnything"));
3607 internalOptions = InternalTaskOptions.ContinuationTask;
3610 internalOptions |= InternalTaskOptions.LazyCancellation;
3614 internal void ContinueWithCore(Task continuationTask, TaskScheduler scheduler, CancellationToken cancellationToken,
TaskContinuationOptions options)
3616 TaskContinuation taskContinuation =
new StandardTaskContinuation(continuationTask, options, scheduler);
3617 if (cancellationToken.CanBeCanceled)
3619 if (
IsCompleted || cancellationToken.IsCancellationRequested)
3621 continuationTask.AssignCancellationToken(cancellationToken,
null,
null);
3625 continuationTask.AssignCancellationToken(cancellationToken,
this, taskContinuation);
3628 if (continuationTask.IsCompleted)
3634 TplEtwProvider log = TplEtwProvider.Log;
3635 if (log.IsEnabled())
3637 log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id,
CurrentId ?? 0, continuationTask.Id);
3640 if (!AddTaskContinuation(taskContinuation, addBeforeOthers:
false))
3642 taskContinuation.Run(
this, bCanInlineContinuationTask:
true);
3646 internal void AddCompletionAction(ITaskCompletionAction action)
3648 AddCompletionAction(action, addBeforeOthers:
false);
3651 private void AddCompletionAction(ITaskCompletionAction action,
bool addBeforeOthers)
3653 if (!AddTaskContinuation(action, addBeforeOthers))
3655 action.Invoke(
this);
3659 private bool AddTaskContinuationComplex(
object tc,
bool addBeforeOthers)
3661 object continuationObject = m_continuationObject;
3662 if (continuationObject != s_taskCompletionSentinel && !(continuationObject is
List<object>))
3665 list.Add(continuationObject);
3666 Interlocked.CompareExchange(ref m_continuationObject, list, continuationObject);
3673 if (m_continuationObject != s_taskCompletionSentinel)
3677 list2.
RemoveAll(s_IsTaskContinuationNullPredicate);
3679 if (addBeforeOthers)
3694 private bool AddTaskContinuation(
object tc,
bool addBeforeOthers)
3700 if (m_continuationObject !=
null || Interlocked.CompareExchange(ref m_continuationObject, tc,
null) !=
null)
3702 return AddTaskContinuationComplex(tc, addBeforeOthers);
3707 internal void RemoveContinuation(
object continuationObject)
3709 object continuationObject2 = m_continuationObject;
3710 if (continuationObject2 == s_taskCompletionSentinel)
3717 if (Interlocked.CompareExchange(ref m_continuationObject,
new List<object>(), continuationObject) == continuationObject)
3727 if (m_continuationObject != s_taskCompletionSentinel)
3729 int num = list.IndexOf(continuationObject);
3746 [__DynamicallyInvokable]
3765 [__DynamicallyInvokable]
3769 if (num < -1 || num >
int.MaxValue)
3773 return WaitAll(tasks, (
int)num);
3788 [__DynamicallyInvokable]
3803 [__DynamicallyInvokable]
3806 WaitAll(tasks, -1, cancellationToken);
3823 [__DynamicallyInvokable]
3830 if (millisecondsTimeout < -1)
3841 for (
int num = tasks.Length - 1; num >= 0; num--)
3843 Task task = tasks[num];
3848 bool flag4 = task.IsCompleted;
3851 if (millisecondsTimeout != -1 || cancellationToken.
CanBeCanceled)
3853 AddToList(task, ref list, tasks.Length);
3857 flag4 = (task.WrappedTryRunInline() && task.IsCompleted);
3860 AddToList(task, ref list, tasks.Length);
3870 else if (task.IsCanceled)
3874 if (task.IsWaitNotificationEnabled)
3876 AddToList(task, ref list2, 1);
3882 flag3 = WaitAllBlockingCore(list, millisecondsTimeout, cancellationToken);
3885 foreach (
Task item
in list)
3891 else if (item.IsCanceled)
3895 if (item.IsWaitNotificationEnabled)
3897 AddToList(item, ref list2, 1);
3903 if (flag3 && list2 !=
null)
3905 foreach (
Task item2
in list2)
3907 if (item2.NotifyDebuggerOfWaitCompletionIfNecessary())
3913 if (flag3 && (flag | flag2))
3919 foreach (
Task t
in tasks)
3921 AddExceptionsForCompletedTask(ref exceptions, t);
3928 private static void AddToList<T>(T item, ref
List<T> list,
int initSize)
3937 private static bool WaitAllBlockingCore(
List<Task> tasks,
int millisecondsTimeout, CancellationToken cancellationToken)
3940 SetOnCountdownMres setOnCountdownMres =
new SetOnCountdownMres(tasks.
Count);
3943 foreach (Task task
in tasks)
3945 task.AddCompletionAction(setOnCountdownMres, addBeforeOthers:
true);
3947 flag = setOnCountdownMres.Wait(millisecondsTimeout, cancellationToken);
3954 foreach (Task task2
in tasks)
3956 if (!task2.IsCompleted)
3958 task2.RemoveContinuation(setOnCountdownMres);
3965 internal static void FastWaitAll(Task[] tasks)
3968 for (
int num = tasks.Length - 1; num >= 0; num--)
3972 tasks[num].WrappedTryRunInline();
3975 for (
int num2 = tasks.Length - 1; num2 >= 0; num2--)
3977 Task task = tasks[num2];
3978 task.SpinThenBlockingWait(-1,
default(CancellationToken));
3979 AddExceptionsForCompletedTask(ref exceptions, task);
3981 if (exceptions !=
null)
3983 throw new AggregateException(exceptions);
3987 internal static void AddExceptionsForCompletedTask(ref
List<Exception> exceptions, Task t)
3989 AggregateException exceptions2 = t.GetExceptions(includeTaskCanceledExceptions:
true);
3990 if (exceptions2 !=
null)
3992 t.UpdateExceptionObservedStatus();
3993 if (exceptions ==
null)
3997 exceptions.AddRange(exceptions2.InnerExceptions);
4008 [__DynamicallyInvokable]
4025 [__DynamicallyInvokable]
4029 if (num < -1 || num >
int.MaxValue)
4033 return WaitAny(tasks, (
int)num);
4045 [__DynamicallyInvokable]
4048 return WaitAny(tasks, -1, cancellationToken);
4061 [__DynamicallyInvokable]
4079 [__DynamicallyInvokable]
4086 if (millisecondsTimeout < -1)
4092 for (
int i = 0; i < tasks.Length; i++)
4094 Task task = tasks[i];
4099 if (num == -1 && task.IsCompleted)
4104 if (num == -1 && tasks.Length != 0)
4107 if (task2.
Wait(millisecondsTimeout, cancellationToken))
4120 [__DynamicallyInvokable]
4129 [__DynamicallyInvokable]
4132 return FromException<VoidTaskResult>(exception);
4139 [__DynamicallyInvokable]
4142 if (exception ==
null)
4147 bool flag = task.TrySetException(exception);
4151 [FriendAccessAllowed]
4165 [__DynamicallyInvokable]
4168 return FromCancellation(cancellationToken);
4171 [FriendAccessAllowed]
4178 return new Task<TResult>(canceled:
true,
default(TResult),
TaskCreationOptions.None, cancellationToken);
4186 [__DynamicallyInvokable]
4189 return FromCancellation<TResult>(cancellationToken);
4194 if (exception ==
null)
4198 Task<TResult> task =
new Task<TResult>();
4208 [__DynamicallyInvokable]
4211 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
4223 [__DynamicallyInvokable]
4226 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
4236 [__DynamicallyInvokable]
4239 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
4252 [__DynamicallyInvokable]
4255 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
4263 [__DynamicallyInvokable]
4276 [__DynamicallyInvokable]
4279 if (
function ==
null)
4283 if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource)
4285 cancellationToken.ThrowIfSourceDisposed();
4289 return FromCancellation(cancellationToken);
4292 return new UnwrapPromise<VoidTaskResult>(outerTask, lookForOce:
true);
4300 [__DynamicallyInvokable]
4314 [__DynamicallyInvokable]
4317 if (
function ==
null)
4321 if (AppContextSwitches.ThrowExceptionIfDisposedCancellationTokenSource)
4323 cancellationToken.ThrowIfSourceDisposed();
4327 return FromCancellation<TResult>(cancellationToken);
4330 return new UnwrapPromise<TResult>(outerTask, lookForOce:
true);
4338 [__DynamicallyInvokable]
4352 [__DynamicallyInvokable]
4356 if (num < -1 || num >
int.MaxValue)
4360 return Delay((
int)num, cancellationToken);
4367 [__DynamicallyInvokable]
4380 [__DynamicallyInvokable]
4383 if (millisecondsDelay < -1)
4389 return FromCancellation(cancellationToken);
4391 if (millisecondsDelay == 0)
4395 DelayPromise delayPromise =
new DelayPromise(cancellationToken);
4398 delayPromise.Registration = cancellationToken.InternalRegisterWithoutEC(delegate(
object state)
4400 ((DelayPromise)state).Complete();
4403 if (millisecondsDelay != -1)
4405 delayPromise.Timer =
new Timer(delegate(
object state)
4407 ((DelayPromise)state).Complete();
4408 }, delayPromise, millisecondsDelay, -1);
4409 delayPromise.Timer.KeepRootedWhileScheduled();
4411 return delayPromise;
4419 [__DynamicallyInvokable]
4428 if (collection !=
null)
4431 array =
new Task[collection.Count];
4432 foreach (
Task task
in tasks)
4438 array[num++] = task;
4440 return InternalWhenAll(array);
4447 foreach (
Task task2
in tasks)
4455 return InternalWhenAll(list.ToArray());
4463 [__DynamicallyInvokable]
4470 int num = tasks.Length;
4473 return InternalWhenAll(tasks);
4476 for (
int i = 0; i < num; i++)
4478 Task task = tasks[i];
4485 return InternalWhenAll(array);
4488 private static Task InternalWhenAll(
Task[] tasks)
4490 if (tasks.Length != 0)
4492 return new WhenAllPromise(tasks);
4503 [__DynamicallyInvokable]
4512 if (collection !=
null)
4522 array[num++] = task;
4524 return InternalWhenAll(array);
4539 return InternalWhenAll(list.ToArray());
4548 [__DynamicallyInvokable]
4555 int num = tasks.Length;
4558 return InternalWhenAll(tasks);
4561 for (
int i = 0; i < num; i++)
4570 return InternalWhenAll(array);
4575 if (tasks.Length != 0)
4577 return new WhenAllPromise<TResult>(tasks);
4587 [__DynamicallyInvokable]
4594 if (tasks.Length == 0)
4598 int num = tasks.Length;
4600 for (
int i = 0; i < num; i++)
4602 Task task = tasks[i];
4617 [__DynamicallyInvokable]
4625 foreach (
Task task
in tasks)
4633 if (list.Count == 0)
4646 [__DynamicallyInvokable]
4659 [__DynamicallyInvokable]
4666 [FriendAccessAllowed]
4667 internal static Task<TResult> CreateUnwrapPromise<TResult>(
Task outerTask,
bool lookForOce)
4669 return new UnwrapPromise<TResult>(outerTask, lookForOce);
4672 internal virtual Delegate[] GetDelegateContinuationsForDebugger()
4674 if (m_continuationObject !=
this)
4676 return GetDelegatesFromContinuationObject(m_continuationObject);
4681 internal static Delegate[] GetDelegatesFromContinuationObject(
object continuationObject)
4683 if (continuationObject !=
null)
4688 return new Delegate[1]
4690 AsyncMethodBuilderCore.TryGetStateMachineForDebugger(action)
4693 TaskContinuation taskContinuation = continuationObject as TaskContinuation;
4694 if (taskContinuation !=
null)
4696 return taskContinuation.GetDelegateContinuationsForDebugger();
4698 Task task = continuationObject as Task;
4701 Delegate[] delegateContinuationsForDebugger = task.GetDelegateContinuationsForDebugger();
4702 if (delegateContinuationsForDebugger !=
null)
4704 return delegateContinuationsForDebugger;
4707 ITaskCompletionAction taskCompletionAction = continuationObject as ITaskCompletionAction;
4708 if (taskCompletionAction !=
null)
4711 ITaskCompletionAction taskCompletionAction2 = taskCompletionAction;
4712 obj[0] =
new Action<Task>(taskCompletionAction2.Invoke);
4719 foreach (
object item
in list)
4721 Delegate[] delegatesFromContinuationObject = GetDelegatesFromContinuationObject(item);
4722 if (delegatesFromContinuationObject !=
null)
4724 Delegate[] array = delegatesFromContinuationObject;
4725 foreach (Delegate @delegate
in array)
4727 if ((
object)@delegate !=
null)
4729 list2.
Add(@delegate);
4740 private static Task GetActiveTaskFromId(
int taskId)
4743 s_currentActiveTasks.TryGetValue(taskId, out value);
4747 private static Task[] GetActiveTasks()
static Task< Task > WhenAny(params Task[] tasks)
Creates a task that will complete when any of the supplied tasks have completed.
static new TaskFactory< TResult > Factory
Provides access to factory methods for creating and configuring T:System.Threading....
bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
Waits for the T:System.Threading.Tasks.Task to complete execution. The wait terminates if a timeout i...
static Task< TResult[]> WhenAll< TResult >(IEnumerable< Task< TResult >> tasks)
Creates a task that will complete when all of the T:System.Threading.Tasks.Task`1 objects in an enume...
static TaskScheduler?? Current
Gets the T:System.Threading.Tasks.TaskScheduler associated with the currently executing task.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Task ContinueWith(Action< Task > continuationAction, TaskContinuationOptions continuationOptions)
Creates a continuation that executes when the target task completes according to the specified T:Syst...
void Dispose()
Releases all resources used by the current instance of the T:System.Threading.ManualResetEventSlim cl...
Task(Func< TResult > function, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified function and creation options.
Propagates notification that operations should be canceled.
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Configures an awaiter used to await this T:System.Threading.Tasks.Task`1.
delegate void ContextCallback(object state)
Represents a method to be called within a new context.
Task(Func< TResult > function)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified function.
Encapsulates operating system–specific objects that wait for exclusive access to shared resources.
void ThrowIfCancellationRequested()
Throws a T:System.OperationCanceledException if this token has had cancellation requested.
int Count
Gets the number of elements contained in the T:System.Collections.Generic.List`1.
Task ContinueWith(Action< Task< TResult >, object > continuationAction, object state, CancellationToken cancellationToken)
Creates a continuation that executes when the target T:System.Threading.Tasks.Task`1 completes.
Task ContinueWith(Action< Task< TResult >> continuationAction, CancellationToken cancellationToken)
Creates a cancelable continuation that executes asynchronously when the target T:System....
TResult Result
Gets the result value of this T:System.Threading.Tasks.Task`1.
static Task WhenAll(params Task[] tasks)
Creates a task that will complete when all of the T:System.Threading.Tasks.Task objects in an array h...
Provides the base class for a generic read-only collection.
static void SuppressFinalize(object obj)
Requests that the common language runtime not call the finalizer for the specified object.
void Start()
Starts the T:System.Threading.Tasks.Task, scheduling it for execution to the current T:System....
static int WaitAny(Task[] tasks, TimeSpan timeout)
Waits for any of the provided T:System.Threading.Tasks.Task objects to complete execution within a sp...
TaskStatus Status
Gets the T:System.Threading.Tasks.TaskStatus of this task.
No initialization action.
Task(Action< object > action, object state, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task with the specified action, state, and options.
static YieldAwaitable Yield()
Creates an awaitable task that asynchronously yields back to the current context when awaited.
TaskStatus
Represents the current stage in the lifecycle of a T:System.Threading.Tasks.Task.
Represents an object that handles the low-level work of queuing tasks onto threads.
Task ContinueWith(Action< Task< TResult >, object > continuationAction, object state, TaskScheduler scheduler)
Creates a continuation that executes when the target T:System.Threading.Tasks.Task`1 completes.
TaskContinuationOptions
Specifies the behavior for a task that is created by using the M:System.Threading....
The exception that is thrown when the value of an argument is outside the allowable range of values a...
Task(Func< TResult > function, CancellationToken cancellationToken)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified function.
static Task< Task > WhenAny(IEnumerable< Task > tasks)
Creates a task that will complete when any of the supplied tasks have completed.
void Start(TaskScheduler scheduler)
Starts the T:System.Threading.Tasks.Task, scheduling it for execution to the specified T:System....
static void KeepAlive(object obj)
References the specified object, which makes it ineligible for garbage collection from the start of t...
static Task Run(Func< Task > function)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by func...
static Task Delay(int millisecondsDelay)
Creates a task that completes after a time delay.
double TotalMilliseconds
Gets the value of the current T:System.TimeSpan structure expressed in whole and fractional milliseco...
static bool WaitAll(Task[] tasks, TimeSpan timeout)
Waits for all of the provided cancellable T:System.Threading.Tasks.Task objects to complete execution...
bool CanBeCanceled
Gets whether this token is capable of being in the canceled state.
void RunSynchronously(TaskScheduler scheduler)
Runs the T:System.Threading.Tasks.Task synchronously on the T:System.Threading.Tasks....
static Task Delay(TimeSpan delay)
Creates a task that completes after a specified time interval.
Task ContinueWith(Action< Task, object > continuationAction, object state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Creates a continuation that receives caller-supplied state information and a cancellation token and t...
Exposes the enumerator, which supports a simple iteration over a collection of a specified type....
delegate void Action()
Encapsulates a method that has no parameters and does not return a value.
static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Waits for all of the provided T:System.Threading.Tasks.Task objects to complete execution within a sp...
WaitHandle WaitHandle
Gets the underlying T:System.Threading.WaitHandle object for this T:System.Threading....
Task(Action< object > action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task with the specified action, state, and options.
static int WaitAny(Task[] tasks, int millisecondsTimeout)
Waits for any of the provided T:System.Threading.Tasks.Task objects to complete execution within a sp...
Task(Func< object, TResult > function, object state, CancellationToken cancellationToken)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified action, state,...
bool IsCancellationRequested
Gets whether cancellation has been requested for this token.
static Task Run(Func< Task > function, CancellationToken cancellationToken)
Queues the specified work to run on the thread pool and returns a proxy for the task returned by func...
Task ContinueWith(Action< Task, object > continuationAction, object state, TaskScheduler scheduler)
Creates a continuation that receives caller-supplied state information and executes asynchronously wh...
Defines methods to manipulate generic collections.
Represents one or more errors that occur during application execution.
TaskCreationOptions
Specifies flags that control optional behavior for the creation and execution of tasks.
Task ContinueWith(Action< Task > continuationAction, TaskScheduler scheduler)
Creates a continuation that executes asynchronously when the target T:System.Threading....
static void WaitAll(params Task[] tasks)
Waits for all of the provided T:System.Threading.Tasks.Task objects to complete execution.
bool IsFaulted
Gets whether the T:System.Threading.Tasks.Task completed due to an unhandled exception.
Provides the context for waiting when asynchronously switching into a target environment.
The exception that is thrown when an operation is performed on a disposed object.
Represents an exception whose state is captured at a certain point in code.
static TaskScheduler Default
Gets the default T:System.Threading.Tasks.TaskScheduler instance that is provided by the ....
void Add(T item)
Adds an object to the end of the T:System.Collections.Generic.List`1.
static Task FromCanceled(CancellationToken cancellationToken)
Creates a T:System.Threading.Tasks.Task that's completed due to cancellation with a specified cancell...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Task ContinueWith(Action< Task< TResult >, object > continuationAction, object state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Creates a continuation that executes when the target T:System.Threading.Tasks.Task`1 completes.
The server synchronously processed the message.
Provides information about, and means to manipulate, the current environment and platform....
Represents the status of an asynchronous operation.
Manages the execution context for the current thread. This class cannot be inherited.
Provides an object that waits for the completion of an asynchronous task.
static Task< TResult > FromException< TResult >(Exception exception)
Creates a T:System.Threading.Tasks.Task`1 that's completed with a specified exception.
static Task Delay(int millisecondsDelay, CancellationToken cancellationToken)
Creates a cancellable task that completes after a time delay.
TaskAwaiter GetAwaiter()
Gets an awaiter used to await this T:System.Threading.Tasks.Task.
void Set()
Sets the state of the event to signaled, which allows one or more threads waiting on the event to pro...
Task ContinueWith(Action< Task, object > continuationAction, object state, TaskContinuationOptions continuationOptions)
Creates a continuation that receives caller-supplied state information and executes when the target T...
bool IsCompleted
Gets whether this T:System.Threading.Tasks.Task has completed.
Task(Action action)
Initializes a new T:System.Threading.Tasks.Task with the specified action.
void Insert(int index, T item)
Inserts an element into the T:System.Collections.Generic.List`1 at the specified index.
static void SetCurrentThreadActivityId(Guid activityId)
[Supported in the .NET Framework 4.5.1 and later versions] Sets the activity ID on the current thread...
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.
Task(Func< object, TResult > function, object state, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified action, state,...
Task< TNewResult > ContinueWith< TNewResult >(Func< Task< TResult >, TNewResult > continuationFunction)
Creates a continuation that executes asynchronously when the target T:System.Threading....
Task(Action< object > action, object state, CancellationToken cancellationToken)
Initializes a new T:System.Threading.Tasks.Task with the specified action, state, and options.
static Task FromException(Exception exception)
Creates a T:System.Threading.Tasks.Task that has completed with a specified exception.
CancellationToken CancellationToken
Gets a token associated with the operation that was canceled.
Task ContinueWith(Action< Task > continuationAction, CancellationToken cancellationToken)
Creates a continuation that receives a cancellation token and executes asynchronously when the target...
TaskCreationOptions CreationOptions
Gets the T:System.Threading.Tasks.TaskCreationOptions used to create this task.
object AsyncState
Gets the state object supplied when the T:System.Threading.Tasks.Task was created,...
Provides a mechanism for executing a method on a thread pool thread at specified intervals....
Provides the ability to create events for event tracing for Windows (ETW).
Provides a slimmed down version of T:System.Threading.ManualResetEvent.
void Wait(CancellationToken cancellationToken)
Waits for the T:System.Threading.Tasks.Task to complete execution. The wait terminates if a cancellat...
Provides the basic functionality for propagating a synchronization context in various synchronization...
static Task Run(Action action, CancellationToken cancellationToken)
Queues the specified work to run on the thread pool and returns a T:System.Threading....
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
static Task< TResult > FromCanceled< TResult >(CancellationToken cancellationToken)
Creates a T:System.Threading.Tasks.Task`1 that's completed due to cancellation with a specified cance...
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
virtual void Dispose(bool disposing)
Disposes the T:System.Threading.Tasks.Task, releasing all of its unmanaged resources.
static Task Delay(TimeSpan delay, CancellationToken cancellationToken)
Creates a cancellable task that completes after a specified time interval.
Task ContinueWith(Action< Task, object > continuationAction, object state)
Creates a continuation that receives caller-supplied state information and executes when the target T...
Task ContinueWith(Action< Task > continuationAction)
Creates a continuation that executes asynchronously when the target T:System.Threading....
ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
Configures an awaiter used to await this T:System.Threading.Tasks.Task.
bool? IsSet
Gets whether the event is set.
static Task CompletedTask
Gets a task that has already completed successfully.
MethodImplOptions
Defines the details of how a method is implemented.
bool CompletedSynchronously
Gets a value that indicates whether the asynchronous operation completed synchronously.
Enables communication with a debugger. This class cannot be inherited.
Task(Func< object, TResult > function, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified action, state,...
static CancellationToken None
Returns an empty T:System.Threading.CancellationToken value.
static int WaitAny(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Waits for any of the provided T:System.Threading.Tasks.Task objects to complete execution within a sp...
void Dispose()
Releases all resources used by the current instance of the T:System.Threading.Tasks....
void RunSynchronously()
Runs the T:System.Threading.Tasks.Task synchronously on the current T:System.Threading....
int Id
Gets an ID for this T:System.Threading.Tasks.Task instance.
Controls the system garbage collector, a service that automatically reclaims unused memory.
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
static Task WhenAll(IEnumerable< Task > tasks)
Creates a task that will complete when all of the T:System.Threading.Tasks.Task objects in an enumera...
MethodInfo Method
Gets the method represented by the delegate.
static ExecutionContext Capture()
Captures the execution context from the current thread.
The exception that is thrown when one of the arguments provided to a method is not valid.
static Task< Task< TResult > > WhenAny< TResult >(params Task< TResult >[] tasks)
Creates a task that will complete when any of the supplied tasks have completed.
An operation that invokes a delegate or lambda expression, such as sampleDelegate....
WaitHandle AsyncWaitHandle
Gets a T:System.Threading.WaitHandle that is used to wait for an asynchronous operation to complete.
bool Wait(int millisecondsTimeout)
Waits for the T:System.Threading.Tasks.Task to complete execution within a specified number of millis...
Task(Action action, CancellationToken cancellationToken)
Initializes a new T:System.Threading.Tasks.Task with the specified action and T:System....
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
The exception that is thrown in a thread upon cancellation of an operation that the thread was execut...
void Wait()
Waits for the T:System.Threading.Tasks.Task to complete execution.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
AggregateException Exception
Gets the T:System.AggregateException that caused the T:System.Threading.Tasks.Task to end prematurely...
static int WaitAny(params Task[] tasks)
Waits for any of the provided T:System.Threading.Tasks.Task objects to complete execution.
ThreadState
Specifies the current execution state of the thread.
bool Wait(TimeSpan timeout)
Waits for the T:System.Threading.Tasks.Task to complete execution within a specified time interval.
static void WaitAll(Task[] tasks, CancellationToken cancellationToken)
Waits for all of the provided T:System.Threading.Tasks.Task objects to complete execution unless the ...
Task ContinueWith(Action< Task< TResult >> continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Creates a continuation that executes according the condition specified in continuationOptions .
Task(Func< object, TResult > function, object state)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified function and state.
Represents a time interval.To browse the .NET Framework source code for this type,...
static bool WaitAll(Task[] tasks, int millisecondsTimeout)
Waits for all of the provided T:System.Threading.Tasks.Task objects to complete execution within a sp...
int Capacity
Gets or sets the total number of elements the internal data structure can hold without resizing.
Task ContinueWith(Action< Task< TResult >> continuationAction, TaskContinuationOptions continuationOptions)
Creates a continuation that executes according the condition specified in continuationOptions .
static Task< TResult > FromResult< TResult >(TResult result)
Creates a T:System.Threading.Tasks.Task`1 that's completed successfully with the specified result.
Task(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task with the specified action and creation options.
static Task Run(Action action)
Queues the specified work to run on the thread pool and returns a T:System.Threading....
The exception that is thrown when a method call is invalid for the object's current state.
Task ContinueWith(Action< Task, object > continuationAction, object state, CancellationToken cancellationToken)
Creates a continuation that receives caller-supplied state information and a cancellation token and t...
int RemoveAll(Predicate< T > match)
Removes all the elements that match the conditions defined by the specified predicate.
Task ContinueWith(Action< Task< TResult >> continuationAction)
Creates a continuation that executes asynchronously when the target task completes.
Task(Action action, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task with the specified action and creation options.
Task< TResult > ContinueWith< TResult >(Func< Task, TResult > continuationFunction)
Creates a continuation that executes asynchronously when the target T:System.Threading....
Task ContinueWith(Action< Task< TResult >, object > continuationAction, object state)
Creates a continuation that that is passed state information and that executes when the target T:Syst...
new TaskAwaiter< TResult > GetAwaiter()
Gets an awaiter used to await this T:System.Threading.Tasks.Task`1.
static void NotifyOfCrossThreadDependency()
Notifies a debugger that execution is about to enter a path that involves a cross-thread dependency.
Provides support for creating and scheduling T:System.Threading.Tasks.Task`1 objects.
Task ContinueWith(Action< Task< TResult >, object > continuationAction, object state, TaskContinuationOptions continuationOptions)
Creates a continuation that executes when the target T:System.Threading.Tasks.Task`1 completes.
T [] ToArray()
Copies the elements of the T:System.Collections.Generic.List`1 to a new array.
Task(Action< object > action, object state)
Initializes a new T:System.Threading.Tasks.Task with the specified action and state.
Task(Func< TResult > function, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Initializes a new T:System.Threading.Tasks.Task`1 with the specified function and creation options.
DebuggerBrowsableState
Provides display instructions for the debugger.
static Task< TResult > Run< TResult >(Func< TResult > function)
Queues the specified work to run on the thread pool and returns a T:System.Threading....
Provides atomic operations for variables that are shared by multiple threads.
Task ContinueWith(Action< Task > continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Creates a continuation that executes when the target task competes according to the specified T:Syste...
static ? int? CurrentId
Returns the ID of the currently executing T:System.Threading.Tasks.Task.
static int WaitAny(Task[] tasks, CancellationToken cancellationToken)
Waits for any of the provided T:System.Threading.Tasks.Task objects to complete execution unless the ...
Task ContinueWith(Action< Task< TResult >> continuationAction, TaskScheduler scheduler)
Creates a continuation that executes asynchronously when the target T:System.Threading....
Attribute can be applied to a delegate.
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.