Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Task.cs
Go to the documentation of this file.
8
10
12[DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}, Result = {DebuggerDisplayResultDescription}")]
13public class Task<TResult> : Task
14{
15 internal static class TaskWhenAnyCast
16 {
18 }
19
20 internal static readonly Task<TResult> s_defaultResultTask = TaskCache.CreateCacheableTask(default(TResult));
21
23
24 internal TResult m_result;
25
27 {
28 get
29 {
30 if (!base.IsCompletedSuccessfully)
31 {
33 }
34 TResult result = m_result;
35 return result?.ToString() ?? "";
36 }
37 }
38
39 private string DebuggerDisplayMethodDescription => m_action?.Method.ToString() ?? "{null}";
40
43 {
44 get
45 {
46 if (!base.IsWaitNotificationEnabledOrNotRanToCompletion)
47 {
48 return m_result;
49 }
51 }
52 }
53
55
57
58 internal Task()
59 {
60 }
61
64 {
65 }
66
67 internal Task(TResult result)
69 {
70 m_result = result;
71 }
72
75 {
76 if (!canceled)
77 {
78 m_result = result;
79 }
80 }
81
86
91
96
101
106
111
116
121
126
131
146
161
162 internal bool TrySetResult(TResult result)
163 {
164 bool result2 = false;
165 if (AtomicStateUpdate(67108864, 90177536))
166 {
167 m_result = result;
170 if (contingentProperties != null)
171 {
173 contingentProperties.SetCompleted();
174 }
176 result2 = true;
177 }
178 return result2;
179 }
180
181 internal void DangerousSetResult(TResult result)
182 {
183 if (m_contingentProperties?.m_parent != null)
184 {
185 bool flag = TrySetResult(result);
186 return;
187 }
188 m_result = result;
189 m_stateFlags |= 16777216;
190 }
191
193 {
194 if (!base.IsCompleted)
195 {
196 InternalWait(-1, default(CancellationToken));
197 }
199 {
201 }
202 if (!base.IsCompletedSuccessfully)
203 {
205 }
206 return m_result;
207 }
208
209 internal override void InnerInvoke()
210 {
211 if (m_action is Func<TResult> func)
212 {
213 m_result = func();
214 }
216 {
218 }
219 }
220
222 {
223 return new TaskAwaiter<TResult>(this);
224 }
225
230
232 {
233 return WaitAsync(uint.MaxValue, cancellationToken);
234 }
235
240
245
247 {
248 if (base.IsCompleted || (!cancellationToken.CanBeCanceled && millisecondsTimeout == uint.MaxValue))
249 {
250 return this;
251 }
252 if (cancellationToken.IsCancellationRequested)
253 {
255 }
256 if (millisecondsTimeout == 0)
257 {
259 }
261 }
262
267
272
277
282
287
303
308
313
318
323
328
344
349
354
359
364
369
385
390
395
400
405
410
426}
427[DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskDebugView))]
428[DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}")]
429public class Task : IAsyncResult, IDisposable
430{
431 [Flags]
432 internal enum TaskStateFlags
433 {
434 Started = 0x10000,
435 DelegateInvoked = 0x20000,
436 Disposed = 0x40000,
438 CancellationAcknowledged = 0x100000,
439 Faulted = 0x200000,
440 Canceled = 0x400000,
441 WaitingOnChildren = 0x800000,
442 RanToCompletion = 0x1000000,
443 WaitingForActivation = 0x2000000,
444 CompletionReserved = 0x4000000,
445 WaitCompletionNotification = 0x10000000,
446 ExecutionContextIsNull = 0x20000000,
447 TaskScheduledWasFired = 0x40000000,
448 CompletedMask = 0x1600000,
449 OptionsMask = 0xFFFF
450 }
451
452 internal sealed class ContingentProperties
453 {
455
457
459
461
463
464 internal volatile int m_internalCancellationRequested;
465
466 internal volatile int m_completionCountdown = 1;
467
469
470 internal Task m_parent;
471
472 internal void SetCompleted()
473 {
474 m_completionEvent?.Set();
475 }
476
478 {
479 if (m_cancellationRegistration != null)
480 {
481 try
482 {
483 m_cancellationRegistration.Value.Dispose();
484 }
486 {
487 }
489 }
490 }
491 }
492
493 private protected sealed class CancellationPromise<TResult> : Task<TResult>, ITaskCompletionAction
494 {
495 private readonly Task _task;
496
498
499 private readonly TimerQueueTimer _timer;
500
501 bool ITaskCompletionAction.InvokeMayRunArbitraryCode => true;
502
504 {
505 _task = source;
507 if (millisecondsDelay != uint.MaxValue)
508 {
510 {
512 if (cancellationPromise2.TrySetException(new TimeoutException()))
513 {
514 cancellationPromise2.Cleanup();
515 }
516 }, this, millisecondsDelay, uint.MaxValue, flowExecutionContext: false);
517 }
519 {
521 if (cancellationPromise.TrySetCanceled(cancellationToken))
522 {
523 cancellationPromise.Cleanup();
524 }
525 }, this);
526 if (base.IsCompleted)
527 {
528 Cleanup();
529 }
530 }
531
533 {
534 if (completingTask.Status switch
535 {
536 TaskStatus.Canceled => TrySetCanceled(completingTask.CancellationToken, completingTask.GetCancellationExceptionDispatchInfo()),
537 TaskStatus.Faulted => TrySetException(completingTask.GetExceptionDispatchInfos()),
538 _ => (completingTask is Task<TResult> task) ? TrySetResult(task.Result) : TrySetResult(),
539 })
540 {
541 Cleanup();
542 }
543 }
544
545 private void Cleanup()
546 {
548 _timer?.Close();
550 }
551 }
552
554 {
555 public bool InvokeMayRunArbitraryCode => false;
556
558 : base(initialState: false, 0)
559 {
560 }
561
563 {
564 Set();
565 }
566 }
567
569 {
570 private int _count;
571
572 public bool InvokeMayRunArbitraryCode => false;
573
575 {
576 _count = count;
577 }
578
580 {
582 {
583 Set();
584 }
585 }
586 }
587
588 private class DelayPromise : Task
589 {
590 private static readonly TimerCallback s_timerCallback = TimerCallback;
591
592 private readonly TimerQueueTimer _timer;
593
595 {
596 if (TplEventSource.Log.IsEnabled())
597 {
598 TplEventSource.Log.TraceOperationBegin(base.Id, "Task.Delay", 0L);
599 }
601 {
602 AddToActiveTasks(this);
603 }
604 if (millisecondsDelay != uint.MaxValue)
605 {
607 if (base.IsCompleted)
608 {
609 _timer.Close();
610 }
611 }
612 }
613
614 private static void TimerCallback(object state)
615 {
616 ((DelayPromise)state).CompleteTimedOut();
617 }
618
619 private void CompleteTimedOut()
620 {
621 if (TrySetResult())
622 {
623 Cleanup();
625 {
627 }
628 if (TplEventSource.Log.IsEnabled())
629 {
630 TplEventSource.Log.TraceOperationEnd(base.Id, AsyncCausalityStatus.Completed);
631 }
632 }
633 }
634
635 protected virtual void Cleanup()
636 {
637 _timer?.Close();
638 }
639 }
640
642 {
644
661
662 protected override void Cleanup()
663 {
665 base.Cleanup();
666 }
667 }
668
669 private sealed class WhenAllPromise : Task, ITaskCompletionAction
670 {
671 private readonly Task[] m_tasks;
672
673 private int m_count;
674
675 public bool InvokeMayRunArbitraryCode => true;
676
677 private protected override bool ShouldNotifyDebuggerOfWaitCompletion
678 {
679 get
680 {
681 if (base.ShouldNotifyDebuggerOfWaitCompletion)
682 {
684 }
685 return false;
686 }
687 }
688
690 {
691 if (TplEventSource.Log.IsEnabled())
692 {
693 TplEventSource.Log.TraceOperationBegin(base.Id, "Task.WhenAll", 0L);
694 }
696 {
697 AddToActiveTasks(this);
698 }
699 m_tasks = tasks;
700 m_count = tasks.Length;
701 foreach (Task task in tasks)
702 {
703 if (task.IsCompleted)
704 {
705 Invoke(task);
706 }
707 else
708 {
709 task.AddCompletionAction(this);
710 }
711 }
712 }
713
715 {
716 if (TplEventSource.Log.IsEnabled())
717 {
718 TplEventSource.Log.TraceOperationRelation(base.Id, CausalityRelation.Join);
719 }
721 {
722 return;
723 }
725 Task task = null;
726 for (int i = 0; i < m_tasks.Length; i++)
727 {
728 Task task2 = m_tasks[i];
729 if (task2.IsFaulted)
730 {
731 if (list == null)
732 {
734 }
735 list.AddRange(task2.GetExceptionDispatchInfos());
736 }
737 else if (task2.IsCanceled && task == null)
738 {
739 task = task2;
740 }
741 if (task2.IsWaitNotificationEnabled)
742 {
744 }
745 else
746 {
747 m_tasks[i] = null;
748 }
749 }
750 if (list != null)
751 {
753 return;
754 }
755 if (task != null)
756 {
757 TrySetCanceled(task.CancellationToken, task.GetCancellationExceptionDispatchInfo());
758 return;
759 }
760 if (TplEventSource.Log.IsEnabled())
761 {
762 TplEventSource.Log.TraceOperationEnd(base.Id, AsyncCausalityStatus.Completed);
763 }
765 {
767 }
768 TrySetResult();
769 }
770 }
771
772 private sealed class WhenAllPromise<T> : Task<T[]>, ITaskCompletionAction
773 {
774 private readonly Task<T>[] m_tasks;
775
776 private int m_count;
777
778 public bool InvokeMayRunArbitraryCode => true;
779
780 private protected override bool ShouldNotifyDebuggerOfWaitCompletion
781 {
782 get
783 {
784 if (base.ShouldNotifyDebuggerOfWaitCompletion)
785 {
786 Task[] tasks = m_tasks;
788 }
789 return false;
790 }
791 }
792
794 {
795 m_tasks = tasks;
796 m_count = tasks.Length;
797 if (TplEventSource.Log.IsEnabled())
798 {
799 TplEventSource.Log.TraceOperationBegin(base.Id, "Task.WhenAll", 0L);
800 }
802 {
803 AddToActiveTasks(this);
804 }
805 foreach (Task<T> task in tasks)
806 {
807 if (task.IsCompleted)
808 {
809 Invoke(task);
810 }
811 else
812 {
813 task.AddCompletionAction(this);
814 }
815 }
816 }
817
818 public void Invoke(Task ignored)
819 {
820 if (TplEventSource.Log.IsEnabled())
821 {
822 TplEventSource.Log.TraceOperationRelation(base.Id, CausalityRelation.Join);
823 }
825 {
826 return;
827 }
828 T[] array = new T[m_tasks.Length];
830 Task task = null;
831 for (int i = 0; i < m_tasks.Length; i++)
832 {
833 Task<T> task2 = m_tasks[i];
834 if (task2.IsFaulted)
835 {
836 if (list == null)
837 {
839 }
840 list.AddRange(task2.GetExceptionDispatchInfos());
841 }
842 else if (task2.IsCanceled)
843 {
844 if (task == null)
845 {
846 task = task2;
847 }
848 }
849 else
850 {
851 array[i] = task2.GetResultCore(waitCompletionNotification: false);
852 }
853 if (task2.IsWaitNotificationEnabled)
854 {
856 }
857 else
858 {
859 m_tasks[i] = null;
860 }
861 }
862 if (list != null)
863 {
865 return;
866 }
867 if (task != null)
868 {
869 TrySetCanceled(task.CancellationToken, task.GetCancellationExceptionDispatchInfo());
870 return;
871 }
872 if (TplEventSource.Log.IsEnabled())
873 {
874 TplEventSource.Log.TraceOperationEnd(base.Id, AsyncCausalityStatus.Completed);
875 }
877 {
879 }
881 }
882 }
883
884 private sealed class TwoTaskWhenAnyPromise<TTask> : Task<TTask>, ITaskCompletionAction where TTask : Task
885 {
886 private TTask _task1;
887
888 private TTask _task2;
889
890 public bool InvokeMayRunArbitraryCode => true;
891
892 public TwoTaskWhenAnyPromise(TTask task1, TTask task2)
893 {
894 _task1 = task1;
895 _task2 = task2;
896 if (TplEventSource.Log.IsEnabled())
897 {
898 TplEventSource.Log.TraceOperationBegin(base.Id, "Task.WhenAny", 0L);
899 }
901 {
902 AddToActiveTasks(this);
903 }
904 task1.AddCompletionAction(this);
905 task2.AddCompletionAction(this);
906 if (task1.IsCompleted)
907 {
908 task2.RemoveContinuation(this);
909 }
910 }
911
913 {
914 Task task;
915 if ((task = Interlocked.Exchange(ref _task1, null)) != null)
916 {
917 Task task2 = _task2;
918 _task2 = null;
919 if (TplEventSource.Log.IsEnabled())
920 {
921 TplEventSource.Log.TraceOperationRelation(base.Id, CausalityRelation.Choice);
922 TplEventSource.Log.TraceOperationEnd(base.Id, AsyncCausalityStatus.Completed);
923 }
925 {
927 }
928 if (!task.IsCompleted)
929 {
930 task.RemoveContinuation(this);
931 }
932 else
933 {
934 task2.RemoveContinuation(this);
935 }
936 bool flag = TrySetResult((TTask)completingTask);
937 }
938 }
939 }
940
942 internal static Task t_currentTask;
943
944 internal static int s_taskIdCounter;
945
946 private int m_taskId;
947
949
950 internal object m_stateObject;
951
953
954 internal volatile int m_stateFlags;
955
956 private volatile object m_continuationObject;
957
958 private static readonly object s_taskCompletionSentinel = new object();
959
960 internal static bool s_asyncDebuggingEnabled;
961
963
965
967
968 private static readonly ContextCallback s_ecCallback = delegate(object obj)
969 {
970 Unsafe.As<Task>(obj).InnerInvoke();
971 };
972
974
976
977 private TaskStateFlags StateFlags => (TaskStateFlags)(m_stateFlags & -65536);
978
979 private string DebuggerDisplayMethodDescription => m_action?.Method.ToString() ?? "{null}";
980
982
984 {
985 [MethodImpl(MethodImplOptions.AggressiveInlining)]
986 get
987 {
988 return (m_stateFlags & 0x11000000) != 16777216;
989 }
990 }
991
993
994 internal bool IsWaitNotificationEnabled => (m_stateFlags & 0x10000000) != 0;
995
996 public int Id
997 {
998 get
999 {
1000 if (Volatile.Read(ref m_taskId) == 0)
1001 {
1002 int value = NewId();
1004 }
1005 return m_taskId;
1006 }
1007 }
1008
1009 public static int? CurrentId => InternalCurrent?.Id;
1010
1012
1014 {
1015 get
1016 {
1017 AggregateException result = null;
1018 if (IsFaulted)
1019 {
1021 }
1022 return result;
1023 }
1024 }
1025
1027 {
1028 get
1029 {
1031 if (((uint)stateFlags & 0x200000u) != 0)
1032 {
1033 return TaskStatus.Faulted;
1034 }
1035 if (((uint)stateFlags & 0x400000u) != 0)
1036 {
1037 return TaskStatus.Canceled;
1038 }
1039 if (((uint)stateFlags & 0x1000000u) != 0)
1040 {
1041 return TaskStatus.RanToCompletion;
1042 }
1043 if (((uint)stateFlags & 0x800000u) != 0)
1044 {
1045 return TaskStatus.WaitingForChildrenToComplete;
1046 }
1047 if (((uint)stateFlags & 0x20000u) != 0)
1048 {
1049 return TaskStatus.Running;
1050 }
1051 if (((uint)stateFlags & 0x10000u) != 0)
1052 {
1053 return TaskStatus.WaitingToRun;
1054 }
1055 if (((uint)stateFlags & 0x2000000u) != 0)
1056 {
1057 return TaskStatus.WaitingForActivation;
1058 }
1059 return TaskStatus.Created;
1060 }
1061 }
1062
1063 public bool IsCanceled => (m_stateFlags & 0x600000) == 4194304;
1064
1066 {
1067 get
1068 {
1070 if (contingentProperties != null)
1071 {
1072 if (contingentProperties.m_internalCancellationRequested != 1)
1073 {
1074 return contingentProperties.m_cancellationToken.IsCancellationRequested;
1075 }
1076 return true;
1077 }
1078 return false;
1079 }
1080 }
1081
1083
1084 internal bool IsCancellationAcknowledged => (m_stateFlags & 0x100000) != 0;
1085
1086 public bool IsCompleted
1087 {
1088 get
1089 {
1092 }
1093 }
1094
1095 public bool IsCompletedSuccessfully => (m_stateFlags & 0x1600000) == 16777216;
1096
1098
1099 WaitHandle IAsyncResult.AsyncWaitHandle
1100 {
1101 get
1102 {
1103 if (((uint)m_stateFlags & 0x40000u) != 0)
1104 {
1106 }
1108 }
1109 }
1110
1111 public object? AsyncState => m_stateObject;
1112
1113 bool IAsyncResult.CompletedSynchronously => false;
1114
1116
1117 public static TaskFactory Factory { get; } = new TaskFactory();
1118
1119
1121
1123 {
1124 get
1125 {
1127 if (contingentProperties.m_completionEvent == null)
1128 {
1129 bool isCompleted = IsCompleted;
1131 if (Interlocked.CompareExchange(ref contingentProperties.m_completionEvent, manualResetEventSlim, null) != null)
1132 {
1133 manualResetEventSlim.Dispose();
1134 }
1135 else if (!isCompleted && IsCompleted)
1136 {
1138 }
1139 }
1140 return contingentProperties.m_completionEvent;
1141 }
1142 }
1143
1144 internal bool ExceptionRecorded
1145 {
1146 get
1147 {
1149 if (contingentProperties != null && contingentProperties.m_exceptionsHolder != null)
1150 {
1151 return contingentProperties.m_exceptionsHolder.ContainsFaultList;
1152 }
1153 return false;
1154 }
1155 }
1156
1157 public bool IsFaulted => (m_stateFlags & 0x200000) != 0;
1158
1160 {
1161 get
1162 {
1163 if ((m_stateFlags & 0x20000000) == 536870912)
1164 {
1165 return null;
1166 }
1168 }
1169 set
1170 {
1171 if (value == null)
1172 {
1173 m_stateFlags |= 536870912;
1174 }
1175 else if (value != ExecutionContext.Default)
1176 {
1178 }
1179 }
1180 }
1181
1182 internal bool IsExceptionObservedByParent => (m_stateFlags & 0x80000) != 0;
1183
1184 internal bool IsDelegateInvoked => (m_stateFlags & 0x20000) != 0;
1185
1186 internal static bool AddToActiveTasks(Task task)
1187 {
1189 int id = task.Id;
1191 {
1192 dictionary[id] = task;
1193 }
1194 return true;
1195 }
1196
1197 internal static void RemoveFromActiveTasks(Task task)
1198 {
1200 if (dictionary == null)
1201 {
1202 return;
1203 }
1204 int id = task.Id;
1206 {
1207 dictionary.Remove(id);
1208 }
1209 }
1210
1212 {
1213 if (canceled)
1214 {
1217 {
1218 m_cancellationToken = ct,
1219 m_internalCancellationRequested = 1
1220 };
1221 }
1222 else
1223 {
1225 }
1226 }
1227
1228 internal Task()
1229 {
1230 m_stateFlags = 33555456;
1231 }
1232
1234 {
1235 if (((uint)creationOptions & 0xFFFFFFBBu) != 0)
1236 {
1238 }
1239 if ((creationOptions & TaskCreationOptions.AttachedToParent) != 0)
1240 {
1242 if (internalCurrent != null)
1243 {
1245 }
1246 }
1248 }
1249
1254
1259
1264
1269
1274
1279
1284
1289
1303
1305 {
1306 m_action = action;
1309 if (((uint)creationOptions & 0xFFFFFFA0u) != 0)
1310 {
1312 }
1313 int num = (int)creationOptions | (int)internalOptions;
1314 m_stateFlags = (((object)m_action == null || (internalOptions & InternalTaskOptions.ContinuationTask) != 0) ? (num | 0x2000000) : num);
1316 if (contingentProperties != null)
1317 {
1318 Task parent = contingentProperties.m_parent;
1319 if (parent != null && (creationOptions & TaskCreationOptions.AttachedToParent) != 0 && (parent.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0)
1320 {
1321 parent.AddNewChild();
1322 }
1323 }
1324 if (cancellationToken.CanBeCanceled)
1325 {
1327 }
1328 }
1329
1331 {
1333 contingentProperties.m_cancellationToken = cancellationToken;
1334 try
1335 {
1336 if ((Options & (TaskCreationOptions)13312) != 0)
1337 {
1338 return;
1339 }
1340 if (cancellationToken.IsCancellationRequested)
1341 {
1343 return;
1344 }
1345 CancellationTokenRegistration value = ((antecedent != null) ? cancellationToken.UnsafeRegister(delegate(object t)
1346 {
1348 Task item = tupleSlim.Item1;
1349 Task item2 = tupleSlim.Item2;
1350 item2.RemoveContinuation(tupleSlim.Item3);
1351 item.InternalCancel();
1353 {
1354 ((Task)t).InternalCancel();
1355 }, this));
1356 contingentProperties.m_cancellationRegistration = new StrongBox<CancellationTokenRegistration>(value);
1357 }
1358 catch
1359 {
1361 if (task != null && (Options & TaskCreationOptions.AttachedToParent) != 0 && (task.Options & TaskCreationOptions.DenyChildAttach) == 0)
1362 {
1364 }
1365 throw;
1366 }
1367 }
1368
1369 internal static TaskCreationOptions OptionsMethod(int flags)
1370 {
1371 return (TaskCreationOptions)(flags & 0xFFFF);
1372 }
1373
1374 internal bool AtomicStateUpdate(int newBits, int illegalBits)
1375 {
1377 if ((stateFlags & illegalBits) == 0)
1378 {
1380 {
1382 }
1383 return true;
1384 }
1385 return false;
1386 }
1387
1389 {
1390 int num = m_stateFlags;
1391 while (true)
1392 {
1393 if ((num & illegalBits) != 0)
1394 {
1395 return false;
1396 }
1398 if (num2 == num)
1399 {
1400 break;
1401 }
1402 num = num2;
1403 }
1404 return true;
1405 }
1406
1407 internal bool AtomicStateUpdate(int newBits, int illegalBits, ref int oldFlags)
1408 {
1409 int num = (oldFlags = m_stateFlags);
1410 while (true)
1411 {
1412 if ((num & illegalBits) != 0)
1413 {
1414 return false;
1415 }
1417 if (oldFlags == num)
1418 {
1419 break;
1420 }
1421 num = oldFlags;
1422 }
1423 return true;
1424 }
1425
1426 internal void SetNotificationForWaitCompletion(bool enabled)
1427 {
1428 if (enabled)
1429 {
1430 bool flag = AtomicStateUpdate(268435456, 90177536);
1431 }
1432 else
1433 {
1434 Interlocked.And(ref m_stateFlags, -268435457);
1435 }
1436 }
1437
1439 {
1441 {
1443 return true;
1444 }
1445 return false;
1446 }
1447
1449 {
1450 foreach (Task task in tasks)
1451 {
1452 if (task != null && task.IsWaitNotificationEnabled && task.ShouldNotifyDebuggerOfWaitCompletion)
1453 {
1454 return true;
1455 }
1456 }
1457 return false;
1458 }
1459
1460 [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
1462 {
1463 SetNotificationForWaitCompletion(enabled: false);
1464 }
1465
1466 internal bool MarkStarted()
1467 {
1468 return AtomicStateUpdate(65536, 4259840);
1469 }
1470
1472 {
1473 if ((m_stateFlags & 0x40000000) == 0)
1474 {
1475 m_stateFlags |= 1073741824;
1476 if (TplEventSource.Log.IsEnabled())
1477 {
1480 TplEventSource.Log.TaskScheduled(ts.Id, internalCurrent?.Id ?? 0, Id, task?.Id ?? 0, (int)Options);
1481 }
1482 }
1483 }
1484
1485 internal void AddNewChild()
1486 {
1488 if (contingentProperties.m_completionCountdown == 1)
1489 {
1490 contingentProperties.m_completionCountdown++;
1491 }
1492 else
1493 {
1494 Interlocked.Increment(ref contingentProperties.m_completionCountdown);
1495 }
1496 }
1497
1503
1504 public void Start()
1505 {
1507 }
1508
1510 {
1513 {
1515 }
1516 if (scheduler == null)
1517 {
1519 }
1521 if ((taskCreationOptions & (TaskCreationOptions)1024) != 0)
1522 {
1524 }
1525 if ((taskCreationOptions & (TaskCreationOptions)512) != 0)
1526 {
1528 }
1530 {
1532 }
1534 }
1535
1540
1549
1551 {
1554 if ((taskCreationOptions & (TaskCreationOptions)512) != 0)
1555 {
1556 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_Continuation);
1557 }
1558 if ((taskCreationOptions & (TaskCreationOptions)1024) != 0)
1559 {
1560 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_Promise);
1561 }
1563 {
1564 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_TaskCompleted);
1565 }
1567 {
1568 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_AlreadyStarted);
1569 }
1570 if (MarkStarted())
1571 {
1572 bool flag = false;
1573 try
1574 {
1575 if (!scheduler.TryRunInline(this, taskWasPreviouslyQueued: false))
1576 {
1577 scheduler.InternalQueueTask(this);
1578 flag = true;
1579 }
1581 {
1583 }
1584 return;
1585 }
1587 {
1588 if (!flag)
1589 {
1594 throw ex;
1595 }
1596 throw;
1597 }
1598 }
1599 ThrowHelper.ThrowInvalidOperationException(ExceptionResource.Task_RunSynchronously_TaskCompleted);
1600 }
1601
1612
1613 internal static int NewId()
1614 {
1615 int num;
1616 do
1617 {
1619 }
1620 while (num == 0);
1621 if (TplEventSource.Log.IsEnabled())
1622 {
1623 TplEventSource.Log.NewID(num);
1624 }
1625 return num;
1626 }
1627
1629 {
1630 if ((creationOptions & TaskCreationOptions.AttachedToParent) == 0)
1631 {
1632 return null;
1633 }
1634 return InternalCurrent;
1635 }
1636
1646
1651
1652 private static bool IsCompletedMethod(int flags)
1653 {
1654 return (flags & 0x1600000) != 0;
1655 }
1656
1657 internal void SpinUntilCompleted()
1658 {
1659 SpinWait spinWait = default(SpinWait);
1660 while (!IsCompleted)
1661 {
1662 spinWait.SpinOnce();
1663 }
1664 }
1665
1666 public void Dispose()
1667 {
1668 Dispose(disposing: true);
1669 GC.SuppressFinalize(this);
1670 }
1671
1672 protected virtual void Dispose(bool disposing)
1673 {
1674 if (disposing)
1675 {
1676 if ((Options & (TaskCreationOptions)16384) != 0)
1677 {
1678 return;
1679 }
1680 if (!IsCompleted)
1681 {
1683 }
1685 if (contingentProperties != null)
1686 {
1688 if (completionEvent != null)
1689 {
1690 contingentProperties.m_completionEvent = null;
1691 if (!completionEvent.IsSet)
1692 {
1693 completionEvent.Set();
1694 }
1695 completionEvent.Dispose();
1696 }
1697 }
1698 }
1699 m_stateFlags |= 262144;
1700 }
1701
1703 {
1704 if (needsProtection)
1705 {
1706 if (!MarkStarted())
1707 {
1708 return;
1709 }
1710 }
1711 else
1712 {
1713 m_stateFlags |= 65536;
1714 }
1716 {
1717 AddToActiveTasks(this);
1718 }
1719 if (TplEventSource.Log.IsEnabled() && (Options & (TaskCreationOptions)512) == 0)
1720 {
1721 TplEventSource.Log.TraceOperationBegin(Id, "Task: " + m_action.Method.Name, 0L);
1722 }
1723 try
1724 {
1726 }
1728 {
1732 if ((Options & (TaskCreationOptions)512) == 0)
1733 {
1735 }
1736 throw ex;
1737 }
1738 }
1739
1740 internal void AddException(object exceptionObject)
1741 {
1743 }
1744
1746 {
1748 if (contingentProperties.m_exceptionsHolder == null)
1749 {
1751 if (Interlocked.CompareExchange(ref contingentProperties.m_exceptionsHolder, taskExceptionHolder, null) != null)
1752 {
1753 taskExceptionHolder.MarkAsHandled(calledFromFinalizer: false);
1754 }
1755 }
1757 {
1759 }
1760 }
1761
1763 {
1764 Exception ex = null;
1766 {
1767 ex = new TaskCanceledException(this);
1768 ex.SetCurrentStackTrace();
1769 }
1771 {
1772 return m_contingentProperties.m_exceptionsHolder.CreateExceptionObject(calledFromFinalizer: false, ex);
1773 }
1774 if (ex != null)
1775 {
1776 return new AggregateException(ex);
1777 }
1778 return null;
1779 }
1780
1782 {
1783 return m_contingentProperties.m_exceptionsHolder.GetExceptionDispatchInfos();
1784 }
1785
1787 {
1789 if (contingentProperties == null)
1790 {
1791 return null;
1792 }
1793 return contingentProperties.m_exceptionsHolder?.GetCancellationExceptionDispatchInfo();
1794 }
1795
1805
1807 {
1809 if (targetContext != null)
1810 {
1811 try
1812 {
1813 targetContext.Post(delegate(object state)
1814 {
1815 ((ExceptionDispatchInfo)state).Throw();
1816 }, state2);
1817 return;
1818 }
1819 catch (Exception ex)
1820 {
1822 }
1823 }
1825 {
1826 ((ExceptionDispatchInfo)state).Throw();
1827 }, state2);
1828 }
1829
1831 {
1833 if (task != null && (Options & TaskCreationOptions.AttachedToParent) != 0 && (task.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0 && InternalCurrent == task)
1834 {
1835 m_stateFlags |= 524288;
1836 }
1837 }
1838
1839 internal void Finish(bool userDelegateExecute)
1840 {
1841 if (m_contingentProperties == null)
1842 {
1844 }
1845 else
1846 {
1848 }
1849 }
1850
1852 {
1854 {
1856 return;
1857 }
1859 if (contingentProperties.m_completionCountdown == 1 || Interlocked.Decrement(ref contingentProperties.m_completionCountdown) == 0)
1860 {
1862 }
1863 else
1864 {
1865 AtomicStateUpdate(8388608, 23068672);
1866 }
1867 List<Task> exceptionalChildren = contingentProperties.m_exceptionalChildren;
1868 if (exceptionalChildren == null)
1869 {
1870 return;
1871 }
1873 {
1875 }
1876 }
1877
1878 private void FinishStageTwo()
1879 {
1881 if (contingentProperties != null)
1882 {
1884 }
1885 int num;
1887 {
1888 num = 2097152;
1889 if (TplEventSource.Log.IsEnabled())
1890 {
1891 TplEventSource.Log.TraceOperationEnd(Id, AsyncCausalityStatus.Error);
1892 }
1894 {
1896 }
1897 }
1899 {
1900 num = 4194304;
1901 if (TplEventSource.Log.IsEnabled())
1902 {
1903 TplEventSource.Log.TraceOperationEnd(Id, AsyncCausalityStatus.Canceled);
1904 }
1906 {
1908 }
1909 }
1910 else
1911 {
1912 num = 16777216;
1913 if (TplEventSource.Log.IsEnabled())
1914 {
1915 TplEventSource.Log.TraceOperationEnd(Id, AsyncCausalityStatus.Completed);
1916 }
1918 {
1920 }
1921 }
1924 if (contingentProperties != null)
1925 {
1926 contingentProperties.SetCompleted();
1927 contingentProperties.UnregisterCancellationCallback();
1928 }
1930 }
1931
1932 internal void FinishStageThree()
1933 {
1934 m_action = null;
1936 if (contingentProperties != null)
1937 {
1938 contingentProperties.m_capturedContext = null;
1940 }
1942 }
1943
1945 {
1947 if (task != null && (task.CreationOptions & TaskCreationOptions.DenyChildAttach) == 0 && ((uint)m_stateFlags & 0xFFFFu & 4u) != 0)
1948 {
1950 }
1951 }
1952
1954 {
1956 if (childTask.IsFaulted && !childTask.IsExceptionObservedByParent)
1957 {
1958 if (contingentProperties.m_exceptionalChildren == null)
1959 {
1960 Interlocked.CompareExchange(ref contingentProperties.m_exceptionalChildren, new List<Task>(), null);
1961 }
1962 List<Task> exceptionalChildren = contingentProperties.m_exceptionalChildren;
1963 if (exceptionalChildren != null)
1964 {
1966 {
1968 }
1969 }
1970 }
1971 if (Interlocked.Decrement(ref contingentProperties.m_completionCountdown) == 0)
1972 {
1974 }
1975 }
1976
1978 {
1979 List<Task> exceptionalChildren = props.m_exceptionalChildren;
1980 if (exceptionalChildren == null)
1981 {
1982 return;
1983 }
1985 {
1986 foreach (Task item in exceptionalChildren)
1987 {
1988 if (item.IsFaulted && !item.IsExceptionObservedByParent)
1989 {
1990 TaskExceptionHolder exceptionsHolder = Volatile.Read(ref item.m_contingentProperties).m_exceptionsHolder;
1991 AddException(exceptionsHolder.CreateExceptionObject(calledFromFinalizer: false, null));
1992 }
1993 }
1994 }
1995 props.m_exceptionalChildren = null;
1996 }
1997
1998 internal bool ExecuteEntry()
1999 {
2000 int oldFlags = 0;
2001 if (!AtomicStateUpdate(131072, 23199744, ref oldFlags) && (oldFlags & 0x400000) == 0)
2002 {
2003 return false;
2004 }
2006 {
2008 }
2009 else
2010 {
2012 }
2013 return true;
2014 }
2015
2020
2022 {
2023 m_stateFlags |= 131072;
2025 {
2027 }
2028 else
2029 {
2031 }
2032 }
2033
2035 {
2036 if (!IsCanceled)
2037 {
2039 if ((num & 0x400000) == 0)
2040 {
2042 }
2043 }
2044 }
2045
2047 {
2051 bool flag = log.IsEnabled();
2052 if (flag)
2053 {
2054 if (log.TasksSetActivityIds)
2055 {
2057 }
2058 if (task != null)
2059 {
2060 log.TaskStarted(task.m_taskScheduler.Id, task.Id, Id);
2061 }
2062 else
2063 {
2064 log.TaskStarted(TaskScheduler.Current.Id, 0, Id);
2065 }
2066 log.TraceSynchronousWorkBegin(Id, CausalitySynchronousWork.Execution);
2067 }
2068 try
2069 {
2070 currentTaskSlot = this;
2071 try
2072 {
2074 if (capturedContext == null)
2075 {
2076 InnerInvoke();
2077 }
2078 else if (threadPoolThread == null)
2079 {
2081 }
2082 else
2083 {
2085 }
2086 }
2088 {
2090 }
2091 if (flag)
2092 {
2093 log.TraceSynchronousWorkEnd(CausalitySynchronousWork.Execution);
2094 }
2096 }
2097 finally
2098 {
2100 if (flag)
2101 {
2102 if (task != null)
2103 {
2104 log.TaskCompleted(task.m_taskScheduler.Id, task.Id, Id, IsFaulted);
2105 }
2106 else
2107 {
2108 log.TaskCompleted(TaskScheduler.Current.Id, 0, Id, IsFaulted);
2109 }
2110 if (log.TasksSetActivityIds)
2111 {
2113 }
2114 }
2115 }
2116 }
2117
2118 internal virtual void InnerInvoke()
2119 {
2120 if (m_action is Action action)
2121 {
2122 action();
2123 }
2125 {
2127 }
2128 }
2129
2142
2144 {
2145 return new TaskAwaiter(this);
2146 }
2147
2152
2188
2190 {
2192 {
2194 if (current != null && current.GetType() != typeof(SynchronizationContext))
2195 {
2198 {
2200 }
2201 return;
2202 }
2205 {
2208 {
2210 }
2211 return;
2212 }
2213 }
2215 {
2217 }
2218 }
2219
2220 public static YieldAwaitable Yield()
2221 {
2222 return default(YieldAwaitable);
2223 }
2224
2225 public void Wait()
2226 {
2227 Wait(-1, default(CancellationToken));
2228 }
2229
2230 public bool Wait(TimeSpan timeout)
2231 {
2232 long num = (long)timeout.TotalMilliseconds;
2233 if (num < -1 || num > int.MaxValue)
2234 {
2236 }
2237 return Wait((int)num, default(CancellationToken));
2238 }
2239
2241 {
2243 }
2244
2245 public bool Wait(int millisecondsTimeout)
2246 {
2247 return Wait(millisecondsTimeout, default(CancellationToken));
2248 }
2249
2251 {
2252 if (millisecondsTimeout < -1)
2253 {
2255 }
2257 {
2258 return true;
2259 }
2261 {
2262 return false;
2263 }
2265 {
2267 if (IsCanceled)
2268 {
2269 cancellationToken.ThrowIfCancellationRequested();
2270 }
2272 }
2273 return true;
2274 }
2275
2277 {
2278 return WaitAsync(uint.MaxValue, cancellationToken);
2279 }
2280
2282 {
2284 }
2285
2290
2292 {
2293 if (IsCompleted || (!cancellationToken.CanBeCanceled && millisecondsTimeout == uint.MaxValue))
2294 {
2295 return this;
2296 }
2297 if (cancellationToken.IsCancellationRequested)
2298 {
2300 }
2301 if (millisecondsTimeout == 0)
2302 {
2303 return FromException(new TimeoutException());
2304 }
2306 }
2307
2308 private bool WrappedTryRunInline()
2309 {
2310 if (m_taskScheduler == null)
2311 {
2312 return false;
2313 }
2314 try
2315 {
2317 }
2319 {
2321 }
2322 }
2323
2324 [MethodImpl(MethodImplOptions.NoOptimization)]
2329
2331 {
2332 if (IsCompleted)
2333 {
2334 return true;
2335 }
2337 bool flag = log.IsEnabled();
2338 if (flag)
2339 {
2342 }
2344 bool result = (millisecondsTimeout == -1 && !cancellationToken.CanBeCanceled && WrappedTryRunInline() && IsCompleted) || SpinThenBlockingWait(millisecondsTimeout, cancellationToken);
2345 if (flag)
2346 {
2348 if (internalCurrent2 != null)
2349 {
2350 log.TaskWaitEnd(internalCurrent2.m_taskScheduler.Id, internalCurrent2.Id, Id);
2351 }
2352 else
2353 {
2354 log.TaskWaitEnd(TaskScheduler.Default.Id, 0, Id);
2355 }
2356 log.TaskWaitContinuationComplete(Id);
2357 }
2358 return result;
2359 }
2360
2362 {
2363 bool flag = millisecondsTimeout == -1;
2364 uint num = ((!flag) ? ((uint)Environment.TickCount) : 0u);
2366 if (!flag2)
2367 {
2369 try
2370 {
2372 if (flag)
2373 {
2375 try
2376 {
2378 }
2379 finally
2380 {
2381 if (flag3)
2382 {
2384 }
2385 }
2386 }
2387 else
2388 {
2389 uint num2 = (uint)Environment.TickCount - num;
2391 {
2393 try
2394 {
2396 }
2397 finally
2398 {
2399 if (flag4)
2400 {
2402 }
2403 }
2404 }
2405 }
2406 }
2407 finally
2408 {
2409 if (!IsCompleted)
2410 {
2412 }
2413 }
2414 }
2415 return flag2;
2416 }
2417
2419 {
2420 if (IsCompleted)
2421 {
2422 return true;
2423 }
2424 if (millisecondsTimeout == 0)
2425 {
2426 return false;
2427 }
2429 SpinWait spinWait = default(SpinWait);
2431 {
2432 spinWait.SpinOnce(-1);
2433 if (IsCompleted)
2434 {
2435 return true;
2436 }
2437 }
2438 return false;
2439 }
2440
2441 internal void InternalCancel()
2442 {
2444 bool flag = false;
2445 if (((uint)m_stateFlags & 0x10000u) != 0)
2446 {
2448 try
2449 {
2450 flag = taskScheduler?.TryDequeue(this) ?? false;
2451 }
2453 {
2455 }
2456 }
2458 bool flag2 = false;
2459 if (flag)
2460 {
2461 flag2 = AtomicStateUpdate(4194304, 4325376);
2462 }
2463 else if ((m_stateFlags & 0x10000) == 0)
2464 {
2465 flag2 = AtomicStateUpdate(4194304, 23265280);
2466 }
2467 if (flag2)
2468 {
2470 }
2471 if (ex != null)
2472 {
2473 throw ex;
2474 }
2475 }
2476
2478 {
2479 m_stateFlags |= 4194304;
2481 }
2482
2487
2489 {
2491 if (tokenToRecord != default(CancellationToken))
2492 {
2493 m_contingentProperties.m_cancellationToken = tokenToRecord;
2494 }
2495 if (cancellationException != null)
2496 {
2498 }
2499 }
2500
2502 {
2505 if (contingentProperties != null)
2506 {
2507 contingentProperties.SetCompleted();
2508 contingentProperties.UnregisterCancellationCallback();
2509 }
2510 if (TplEventSource.Log.IsEnabled())
2511 {
2512 TplEventSource.Log.TraceOperationEnd(Id, AsyncCausalityStatus.Canceled);
2513 }
2515 {
2517 }
2519 }
2520
2522 {
2523 m_stateFlags |= 1048576;
2524 }
2525
2526 internal bool TrySetResult()
2527 {
2528 if (AtomicStateUpdate(83886080, 90177536))
2529 {
2531 if (contingentProperties != null)
2532 {
2534 contingentProperties.SetCompleted();
2535 }
2537 return true;
2538 }
2539 return false;
2540 }
2541
2542 internal bool TrySetException(object exceptionObject)
2543 {
2544 bool result = false;
2546 if (AtomicStateUpdate(67108864, 90177536))
2547 {
2550 result = true;
2551 }
2552 return result;
2553 }
2554
2556 {
2557 return TrySetCanceled(tokenToRecord, null);
2558 }
2559
2561 {
2562 bool result = false;
2563 if (AtomicStateUpdate(67108864, 90177536))
2564 {
2567 result = true;
2568 }
2569 return result;
2570 }
2571
2572 internal void FinishContinuations()
2573 {
2575 if (obj != null)
2576 {
2578 }
2579 }
2580
2582 {
2584 bool flag = log.IsEnabled();
2585 if (flag)
2586 {
2587 log.TraceSynchronousWorkBegin(Id, CausalitySynchronousWork.CompletionNotification);
2588 }
2591 {
2592 if (!(continuationObject is Action action))
2593 {
2595 {
2597 {
2600 return;
2601 }
2603 lock (list)
2604 {
2605 }
2606 int count = list.Count;
2607 if (flag2)
2608 {
2609 bool flag3 = false;
2610 for (int i = 0; i < count; i++)
2611 {
2612 object obj = list[i];
2613 if (obj == null)
2614 {
2615 continue;
2616 }
2618 {
2619 if ((continueWithTaskContinuation.m_options & TaskContinuationOptions.ExecuteSynchronously) == 0)
2620 {
2621 list[i] = null;
2622 if (flag)
2623 {
2624 log.RunningContinuationList(Id, i, continueWithTaskContinuation);
2625 }
2627 }
2628 }
2629 else
2630 {
2632 {
2633 continue;
2634 }
2635 if (flag3)
2636 {
2637 list[i] = null;
2638 if (flag)
2639 {
2640 log.RunningContinuationList(Id, i, obj);
2641 }
2643 {
2644 if (obj is Action action2)
2645 {
2647 }
2648 else
2649 {
2650 ((TaskContinuation)obj).Run(this, canInlineContinuationTask: false);
2651 }
2652 }
2653 else
2654 {
2656 }
2657 }
2658 flag3 = true;
2659 }
2660 }
2661 }
2662 for (int j = 0; j < count; j++)
2663 {
2664 object obj2 = list[j];
2665 if (obj2 == null)
2666 {
2667 continue;
2668 }
2669 list[j] = null;
2670 if (flag)
2671 {
2672 log.RunningContinuationList(Id, j, obj2);
2673 }
2675 {
2676 if (!(obj2 is Action action3))
2677 {
2679 {
2680 taskContinuation2.Run(this, flag2);
2681 }
2682 else
2683 {
2685 }
2686 }
2687 else
2688 {
2690 }
2691 }
2692 else
2693 {
2695 }
2696 }
2698 }
2699 else
2700 {
2701 taskContinuation.Run(this, flag2);
2703 }
2704 }
2705 else
2706 {
2709 }
2710 }
2711 else
2712 {
2715 }
2716 }
2717
2719 {
2720 if (allowInlining || !completionAction.InvokeMayRunArbitraryCode)
2721 {
2722 completionAction.Invoke(this);
2723 }
2724 else
2725 {
2727 }
2728 }
2729
2731 {
2732 if (TplEventSource.Log.IsEnabled())
2733 {
2734 TplEventSource.Log.TraceSynchronousWorkEnd(CausalitySynchronousWork.CompletionNotification);
2735 }
2736 }
2737
2742
2747
2752
2757
2762
2778
2783
2788
2793
2798
2803
2819
2824
2829
2834
2839
2844
2860
2865
2870
2875
2880
2885
2901
2903 {
2904 if ((continuationOptions & (TaskContinuationOptions.LongRunning | TaskContinuationOptions.ExecuteSynchronously)) == (TaskContinuationOptions.LongRunning | TaskContinuationOptions.ExecuteSynchronously))
2905 {
2906 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_ESandLR);
2907 }
2908 if (((uint)continuationOptions & 0xFFF0FF80u) != 0)
2909 {
2911 }
2912 if ((continuationOptions & (TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.NotOnRanToCompletion)) == (TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.NotOnRanToCompletion))
2913 {
2914 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.continuationOptions, ExceptionResource.Task_ContinueWith_NotOnAnything);
2915 }
2916 creationOptions = (TaskCreationOptions)(continuationOptions & (TaskContinuationOptions.PreferFairness | TaskContinuationOptions.LongRunning | TaskContinuationOptions.AttachedToParent | TaskContinuationOptions.DenyChildAttach | TaskContinuationOptions.HideScheduler | TaskContinuationOptions.RunContinuationsAsynchronously));
2917 internalOptions = (((continuationOptions & TaskContinuationOptions.LazyCancellation) != 0) ? (InternalTaskOptions.ContinuationTask | InternalTaskOptions.LazyCancellation) : InternalTaskOptions.ContinuationTask);
2918 }
2919
2921 {
2923 if (cancellationToken.CanBeCanceled)
2924 {
2925 if (IsCompleted || cancellationToken.IsCancellationRequested)
2926 {
2927 continuationTask.AssignCancellationToken(cancellationToken, null, null);
2928 }
2929 else
2930 {
2931 continuationTask.AssignCancellationToken(cancellationToken, this, taskContinuation);
2932 }
2933 }
2934 if (continuationTask.IsCompleted)
2935 {
2936 return;
2937 }
2938 if ((Options & (TaskCreationOptions)1024) != 0 && !(this is ITaskCompletionAction))
2939 {
2941 if (log.IsEnabled())
2942 {
2943 log.AwaitTaskContinuationScheduled(TaskScheduler.Current.Id, CurrentId.GetValueOrDefault(), continuationTask.Id);
2944 }
2945 }
2947 {
2949 }
2950 }
2951
2953 {
2955 {
2956 action.Invoke(this);
2957 }
2958 }
2959
2961 {
2964 {
2966 }
2968 {
2969 lock (list)
2970 {
2972 {
2973 if (list.Count == list.Capacity)
2974 {
2975 list.RemoveAll((object l) => l == null);
2976 }
2977 if (addBeforeOthers)
2978 {
2979 list.Insert(0, tc);
2980 }
2981 else
2982 {
2983 list.Add(tc);
2984 }
2985 return true;
2986 }
2987 }
2988 }
2989 return false;
2990 }
2991
2992 private bool AddTaskContinuation(object tc, bool addBeforeOthers)
2993 {
2994 if (IsCompleted)
2995 {
2996 return false;
2997 }
2999 {
3001 }
3002 return true;
3003 }
3004
3006 {
3009 {
3010 return;
3011 }
3013 if (list == null)
3014 {
3016 {
3017 return;
3018 }
3020 }
3021 if (list == null)
3022 {
3023 return;
3024 }
3025 lock (list)
3026 {
3028 {
3029 int num = list.IndexOf(continuationObject);
3030 if (num != -1)
3031 {
3032 list[num] = null;
3033 }
3034 }
3035 }
3036 }
3037
3038 [MethodImpl(MethodImplOptions.NoOptimization)]
3039 [UnsupportedOSPlatform("browser")]
3040 public static void WaitAll(params Task[] tasks)
3041 {
3042 WaitAllCore(tasks, -1, default(CancellationToken));
3043 }
3044
3045 [MethodImpl(MethodImplOptions.NoOptimization)]
3046 [UnsupportedOSPlatform("browser")]
3047 public static bool WaitAll(Task[] tasks, TimeSpan timeout)
3048 {
3049 long num = (long)timeout.TotalMilliseconds;
3050 if (num < -1 || num > int.MaxValue)
3051 {
3053 }
3054 return WaitAllCore(tasks, (int)num, default(CancellationToken));
3055 }
3056
3057 [MethodImpl(MethodImplOptions.NoOptimization)]
3058 [UnsupportedOSPlatform("browser")]
3059 public static bool WaitAll(Task[] tasks, int millisecondsTimeout)
3060 {
3062 }
3063
3064 [MethodImpl(MethodImplOptions.NoOptimization)]
3065 [UnsupportedOSPlatform("browser")]
3070
3071 [MethodImpl(MethodImplOptions.NoOptimization)]
3072 [UnsupportedOSPlatform("browser")]
3077
3078 [UnsupportedOSPlatform("browser")]
3080 {
3081 if (tasks == null)
3082 {
3084 }
3085 if (millisecondsTimeout < -1)
3086 {
3088 }
3089 cancellationToken.ThrowIfCancellationRequested();
3091 List<Task> list = null;
3092 List<Task> list2 = null;
3093 bool flag = false;
3094 bool flag2 = false;
3095 bool flag3 = true;
3096 for (int num = tasks.Length - 1; num >= 0; num--)
3097 {
3098 Task task = tasks[num];
3099 if (task == null)
3100 {
3102 }
3103 bool flag4 = task.IsCompleted;
3104 if (!flag4)
3105 {
3106 if (millisecondsTimeout != -1 || cancellationToken.CanBeCanceled)
3107 {
3108 AddToList(task, ref list, tasks.Length);
3109 }
3110 else
3111 {
3112 flag4 = task.WrappedTryRunInline() && task.IsCompleted;
3113 if (!flag4)
3114 {
3115 AddToList(task, ref list, tasks.Length);
3116 }
3117 }
3118 }
3119 if (flag4)
3120 {
3121 if (task.IsFaulted)
3122 {
3123 flag = true;
3124 }
3125 else if (task.IsCanceled)
3126 {
3127 flag2 = true;
3128 }
3129 if (task.IsWaitNotificationEnabled)
3130 {
3131 AddToList(task, ref list2, 1);
3132 }
3133 }
3134 }
3135 if (list != null)
3136 {
3138 if (flag3)
3139 {
3140 foreach (Task item in list)
3141 {
3142 if (item.IsFaulted)
3143 {
3144 flag = true;
3145 }
3146 else if (item.IsCanceled)
3147 {
3148 flag2 = true;
3149 }
3150 if (item.IsWaitNotificationEnabled)
3151 {
3152 AddToList(item, ref list2, 1);
3153 }
3154 }
3155 }
3157 }
3158 if (flag3 && list2 != null)
3159 {
3160 foreach (Task item2 in list2)
3161 {
3162 if (item2.NotifyDebuggerOfWaitCompletionIfNecessary())
3163 {
3164 break;
3165 }
3166 }
3167 }
3168 if (flag3 && (flag || flag2))
3169 {
3170 if (!flag)
3171 {
3172 cancellationToken.ThrowIfCancellationRequested();
3173 }
3174 foreach (Task t in tasks)
3175 {
3177 }
3179 }
3180 return flag3;
3181 }
3182
3183 private static void AddToList<T>(T item, ref List<T> list, int initSize)
3184 {
3185 if (list == null)
3186 {
3187 list = new List<T>(initSize);
3188 }
3189 list.Add(item);
3190 }
3191
3192 [UnsupportedOSPlatform("browser")]
3194 {
3195 bool flag = false;
3197 try
3198 {
3199 foreach (Task task in tasks)
3200 {
3201 task.AddCompletionAction(setOnCountdownMres, addBeforeOthers: true);
3202 }
3204 }
3205 finally
3206 {
3207 if (!flag)
3208 {
3209 foreach (Task task2 in tasks)
3210 {
3211 if (!task2.IsCompleted)
3212 {
3213 task2.RemoveContinuation(setOnCountdownMres);
3214 }
3215 }
3216 }
3217 }
3218 return flag;
3219 }
3220
3222 {
3224 if (exceptions2 != null)
3225 {
3227 if (exceptions == null)
3228 {
3229 exceptions = new List<Exception>(exceptions2.InnerExceptionCount);
3230 }
3231 exceptions.AddRange(exceptions2.InternalInnerExceptions);
3232 }
3233 }
3234
3235 [MethodImpl(MethodImplOptions.NoOptimization)]
3236 public static int WaitAny(params Task[] tasks)
3237 {
3238 return WaitAnyCore(tasks, -1, default(CancellationToken));
3239 }
3240
3241 [MethodImpl(MethodImplOptions.NoOptimization)]
3242 public static int WaitAny(Task[] tasks, TimeSpan timeout)
3243 {
3244 long num = (long)timeout.TotalMilliseconds;
3245 if (num < -1 || num > int.MaxValue)
3246 {
3248 }
3249 return WaitAnyCore(tasks, (int)num, default(CancellationToken));
3250 }
3251
3252 [MethodImpl(MethodImplOptions.NoOptimization)]
3254 {
3255 return WaitAnyCore(tasks, -1, cancellationToken);
3256 }
3257
3258 [MethodImpl(MethodImplOptions.NoOptimization)]
3259 public static int WaitAny(Task[] tasks, int millisecondsTimeout)
3260 {
3262 }
3263
3264 [MethodImpl(MethodImplOptions.NoOptimization)]
3269
3271 {
3272 if (tasks == null)
3273 {
3275 }
3276 if (millisecondsTimeout < -1)
3277 {
3279 }
3280 cancellationToken.ThrowIfCancellationRequested();
3281 int num = -1;
3282 for (int i = 0; i < tasks.Length; i++)
3283 {
3284 Task task = tasks[i];
3285 if (task == null)
3286 {
3288 }
3289 if (num == -1 && task.IsCompleted)
3290 {
3291 num = i;
3292 }
3293 }
3294 if (num == -1 && tasks.Length != 0)
3295 {
3298 {
3299 num = Array.IndexOf(tasks, task2.Result);
3300 }
3301 else
3302 {
3304 }
3305 }
3307 return num;
3308 }
3309
3310 [MethodImpl(MethodImplOptions.AggressiveInlining)]
3312 {
3313 if (result == null)
3314 {
3315 return Task<TResult>.s_defaultResultTask;
3316 }
3317 if (typeof(TResult).IsValueType)
3318 {
3319 if (typeof(TResult) == typeof(bool))
3320 {
3321 Task<bool> value = (((bool)(object)result) ? TaskCache.s_trueTask : TaskCache.s_falseTask);
3322 return Unsafe.As<Task<TResult>>(value);
3323 }
3324 if (typeof(TResult) == typeof(int))
3325 {
3326 int num = (int)(object)result;
3327 if ((uint)(num - -1) < 10u)
3328 {
3330 return Unsafe.As<Task<TResult>>(value2);
3331 }
3332 }
3333 else if ((typeof(TResult) == typeof(uint) && (uint)(object)result == 0) || (typeof(TResult) == typeof(byte) && (byte)(object)result == 0) || (typeof(TResult) == typeof(sbyte) && (sbyte)(object)result == 0) || (typeof(TResult) == typeof(char) && (char)(object)result == '\0') || (typeof(TResult) == typeof(long) && (long)(object)result == 0L) || (typeof(TResult) == typeof(ulong) && (ulong)(object)result == 0L) || (typeof(TResult) == typeof(short) && (short)(object)result == 0) || (typeof(TResult) == typeof(ushort) && (ushort)(object)result == 0) || (typeof(TResult) == typeof(IntPtr) && (IntPtr)0 == (IntPtr)(object)result) || (typeof(TResult) == typeof(UIntPtr) && (UIntPtr)0u == (UIntPtr)(object)result))
3334 {
3335 return Task<TResult>.s_defaultResultTask;
3336 }
3337 }
3338 return new Task<TResult>(result);
3339 }
3340
3342 {
3343 if (exception == null)
3344 {
3346 }
3347 Task task = new Task();
3348 bool flag = task.TrySetException(exception);
3349 return task;
3350 }
3351
3353 {
3354 if (exception == null)
3355 {
3357 }
3359 bool flag = task.TrySetException(exception);
3360 return task;
3361 }
3362
3364 {
3365 if (!cancellationToken.IsCancellationRequested)
3366 {
3368 }
3369 return new Task(canceled: true, TaskCreationOptions.None, cancellationToken);
3370 }
3371
3373 {
3374 if (!cancellationToken.IsCancellationRequested)
3375 {
3377 }
3378 return new Task<TResult>(canceled: true, default(TResult), TaskCreationOptions.None, cancellationToken);
3379 }
3380
3382 {
3383 Task task = new Task();
3384 bool flag = task.TrySetCanceled(exception.CancellationToken, exception);
3385 return task;
3386 }
3387
3389 {
3391 bool flag = task.TrySetCanceled(exception.CancellationToken, exception);
3392 return task;
3393 }
3394
3395 public static Task Run(Action action)
3396 {
3397 return InternalStartNew(null, action, null, default(CancellationToken), TaskScheduler.Default, TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None);
3398 }
3399
3401 {
3403 }
3404
3406 {
3407 return Task<TResult>.StartNew(null, function, default(CancellationToken), TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default);
3408 }
3409
3411 {
3412 return Task<TResult>.StartNew(null, function, cancellationToken, TaskCreationOptions.DenyChildAttach, InternalTaskOptions.None, TaskScheduler.Default);
3413 }
3414
3415 public static Task Run(Func<Task?> function)
3416 {
3417 return Run(function, default(CancellationToken));
3418 }
3419
3421 {
3422 if (function == null)
3423 {
3425 }
3426 if (cancellationToken.IsCancellationRequested)
3427 {
3429 }
3430 Task<Task> outerTask = Task<Task>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
3432 }
3433
3434 public static Task<TResult> Run<TResult>(Func<Task<TResult>?> function)
3435 {
3436 return Run(function, default(CancellationToken));
3437 }
3438
3440 {
3441 if (function == null)
3442 {
3444 }
3445 if (cancellationToken.IsCancellationRequested)
3446 {
3448 }
3450 return new UnwrapPromise<TResult>(outerTask, lookForOce: true);
3451 }
3452
3453 public static Task Delay(TimeSpan delay)
3454 {
3455 return Delay(delay, default(CancellationToken));
3456 }
3457
3462
3463 public static Task Delay(int millisecondsDelay)
3464 {
3465 return Delay(millisecondsDelay, default(CancellationToken));
3466 }
3467
3469 {
3470 if (millisecondsDelay < -1)
3471 {
3472 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.millisecondsDelay, ExceptionResource.Task_Delay_InvalidMillisecondsDelay);
3473 }
3475 }
3476
3478 {
3479 if (!cancellationToken.IsCancellationRequested)
3480 {
3481 if (millisecondsDelay != 0)
3482 {
3483 if (!cancellationToken.CanBeCanceled)
3484 {
3485 return new DelayPromise(millisecondsDelay);
3486 }
3488 }
3489 return CompletedTask;
3490 }
3492 }
3493
3495 {
3496 long num = (long)timeout.TotalMilliseconds;
3497 if (num < -1 || num > 4294967294u)
3498 {
3500 }
3501 return (uint)num;
3502 }
3503
3505 {
3507 {
3508 if (tasks is Task[] tasks2)
3509 {
3510 return WhenAll(tasks2);
3511 }
3512 int num = 0;
3513 Task[] array = new Task[collection.Count];
3514 foreach (Task task in tasks)
3515 {
3516 if (task == null)
3517 {
3518 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3519 }
3520 array[num++] = task;
3521 }
3522 return InternalWhenAll(array);
3523 }
3524 if (tasks == null)
3525 {
3527 }
3528 List<Task> list = new List<Task>();
3529 foreach (Task task2 in tasks)
3530 {
3531 if (task2 == null)
3532 {
3533 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3534 }
3535 list.Add(task2);
3536 }
3537 return InternalWhenAll(list.ToArray());
3538 }
3539
3540 public static Task WhenAll(params Task[] tasks)
3541 {
3542 if (tasks == null)
3543 {
3545 }
3546 int num = tasks.Length;
3547 if (num == 0)
3548 {
3549 return InternalWhenAll(tasks);
3550 }
3551 Task[] array = new Task[num];
3552 for (int i = 0; i < num; i++)
3553 {
3554 Task task = tasks[i];
3555 if (task == null)
3556 {
3557 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3558 }
3559 array[i] = task;
3560 }
3561 return InternalWhenAll(array);
3562 }
3563
3564 private static Task InternalWhenAll(Task[] tasks)
3565 {
3566 if (tasks.Length != 0)
3567 {
3568 return new WhenAllPromise(tasks);
3569 }
3570 return CompletedTask;
3571 }
3572
3574 {
3576 {
3577 return WhenAll(tasks2);
3578 }
3580 {
3581 int num = 0;
3583 foreach (Task<TResult> task in tasks)
3584 {
3585 if (task == null)
3586 {
3587 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3588 }
3589 array[num++] = task;
3590 }
3591 return InternalWhenAll(array);
3592 }
3593 if (tasks == null)
3594 {
3596 }
3598 foreach (Task<TResult> task2 in tasks)
3599 {
3600 if (task2 == null)
3601 {
3602 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3603 }
3604 list.Add(task2);
3605 }
3606 return InternalWhenAll(list.ToArray());
3607 }
3608
3610 {
3611 if (tasks == null)
3612 {
3614 }
3615 int num = tasks.Length;
3616 if (num == 0)
3617 {
3618 return InternalWhenAll(tasks);
3619 }
3620 Task<TResult>[] array = new Task<TResult>[num];
3621 for (int i = 0; i < num; i++)
3622 {
3624 if (task == null)
3625 {
3626 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3627 }
3628 array[i] = task;
3629 }
3630 return InternalWhenAll(array);
3631 }
3632
3634 {
3635 if (tasks.Length != 0)
3636 {
3637 return new WhenAllPromise<TResult>(tasks);
3638 }
3639 return new Task<TResult[]>(canceled: false, Array.Empty<TResult>(), TaskCreationOptions.None, default(CancellationToken));
3640 }
3641
3643 {
3644 if (tasks == null)
3645 {
3647 }
3648 if (tasks.Length == 2)
3649 {
3650 return WhenAny(tasks[0], tasks[1]);
3651 }
3652 if (tasks.Length == 0)
3653 {
3654 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
3655 }
3656 int num = tasks.Length;
3657 Task[] array = new Task[num];
3658 for (int i = 0; i < num; i++)
3659 {
3660 Task task = tasks[i];
3661 if (task == null)
3662 {
3663 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3664 }
3665 array[i] = task;
3666 }
3668 }
3669
3671 {
3672 if (task1 != null && task2 != null)
3673 {
3674 if (!task1.IsCompleted)
3675 {
3676 if (!task2.IsCompleted)
3677 {
3679 }
3680 return FromResult(task2);
3681 }
3682 return FromResult(task1);
3683 }
3684 throw new ArgumentNullException((task1 == null) ? "task1" : "task2");
3685 }
3686
3688 {
3690 {
3691 if (tasks is Task[] tasks2)
3692 {
3693 return WhenAny(tasks2);
3694 }
3695 int count = collection.Count;
3696 if (count <= 0)
3697 {
3698 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
3699 }
3700 int num = 0;
3701 Task[] array = new Task[count];
3702 foreach (Task task in tasks)
3703 {
3704 if (task == null)
3705 {
3706 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3707 }
3708 array[num++] = task;
3709 }
3711 }
3712 if (tasks == null)
3713 {
3715 }
3716 List<Task> list = new List<Task>();
3717 foreach (Task task2 in tasks)
3718 {
3719 if (task2 == null)
3720 {
3721 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks);
3722 }
3723 list.Add(task2);
3724 }
3725 if (list.Count == 0)
3726 {
3727 ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks);
3728 }
3730 }
3731
3733 {
3734 if (tasks != null && tasks.Length == 2)
3735 {
3736 return WhenAny(tasks[0], tasks[1]);
3737 }
3739 return task.ContinueWith(Task<TResult>.TaskWhenAnyCast.Value, default(CancellationToken), TaskContinuationOptions.DenyChildAttach | TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
3740 }
3741
3743 {
3744 if (task1 != null && task2 != null)
3745 {
3746 if (!task1.IsCompleted)
3747 {
3748 if (!task2.IsCompleted)
3749 {
3751 }
3752 return FromResult(task2);
3753 }
3754 return FromResult(task1);
3755 }
3756 throw new ArgumentNullException((task1 == null) ? "task1" : "task2");
3757 }
3758
3764
3769
3771 {
3772 if (m_continuationObject != this)
3773 {
3775 }
3776 return null;
3777 }
3778
3780 {
3781 if (continuationObject != null)
3782 {
3783 if (continuationObject is Action action)
3784 {
3786 }
3788 {
3789 return taskContinuation.GetDelegateContinuationsForDebugger();
3790 }
3792 {
3793 Delegate[] delegateContinuationsForDebugger = task.GetDelegateContinuationsForDebugger();
3795 {
3797 }
3798 }
3800 {
3801 return new Delegate[1]
3802 {
3804 };
3805 }
3807 {
3809 foreach (object item in list)
3810 {
3813 {
3814 continue;
3815 }
3817 foreach (Delegate @delegate in array)
3818 {
3819 if ((object)@delegate != null)
3820 {
3821 list2.Add(@delegate);
3822 }
3823 }
3824 }
3825 return list2.ToArray();
3826 }
3827 }
3828 return null;
3829 }
3830
3831 private static Task GetActiveTaskFromId(int taskId)
3832 {
3833 Task value = null;
3834 s_currentActiveTasks?.TryGetValue(taskId, out value);
3835 return value;
3836 }
3837}
int IList. IndexOf(object value)
Definition Array.cs:1228
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
MethodInfo Method
Definition Delegate.cs:23
static void NotifyOfCrossThreadDependency()
Definition Debugger.cs:44
static void SetCurrentThreadActivityId(Guid activityId)
static int TickCount
static void SuppressFinalize(object obj)
Definition GC.cs:202
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static ExceptionDispatchInfo Capture(Exception source)
static string TaskT_DebuggerNoResult
Definition SR.cs:1982
Definition SR.cs:7
static void RunInternal(ExecutionContext executionContext, ContextCallback callback, object state)
static readonly ExecutionContext Default
static ? ExecutionContext Capture()
static void RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)
static int CompareExchange(ref int location1, int value, int comparand)
static int Exchange(ref int location1, int value)
static int Decrement(ref int location)
static int Increment(ref int location)
static int And(ref int location1, int value)
static ? SynchronizationContext Current
static void RunOrScheduleAction(Action action, bool allowInlining)
static void UnsafeScheduleAction(Action action, Task task)
static readonly Task< bool > s_trueTask
Definition TaskCache.cs:5
static readonly Task< int >[] s_int32Tasks
Definition TaskCache.cs:9
static readonly Task< bool > s_falseTask
Definition TaskCache.cs:7
static void CommonCWAnyLogicCleanup(Task< Task > continuation)
static Task< Task > CommonCWAnyLogic(IList< Task > tasks, bool isSyncBlocking=false)
static ? TaskScheduler InternalCurrent
bool TryRunInline(Task task, bool taskWasPreviouslyQueued)
readonly CancellationTokenRegistration _registration
Definition Task.cs:497
CancellationPromise(Task source, uint millisecondsDelay, CancellationToken token)
Definition Task.cs:503
volatile List< Task > m_exceptionalChildren
Definition Task.cs:468
StrongBox< CancellationTokenRegistration > m_cancellationRegistration
Definition Task.cs:462
volatile TaskExceptionHolder m_exceptionsHolder
Definition Task.cs:458
volatile ManualResetEventSlim m_completionEvent
Definition Task.cs:456
DelayPromiseWithCancellation(uint millisecondsDelay, CancellationToken token)
Definition Task.cs:645
readonly CancellationTokenRegistration _registration
Definition Task.cs:643
readonly TimerQueueTimer _timer
Definition Task.cs:592
static readonly TimerCallback s_timerCallback
Definition Task.cs:590
static void TimerCallback(object state)
Definition Task.cs:614
DelayPromise(uint millisecondsDelay)
Definition Task.cs:594
void Invoke(Task completingTask)
Definition Task.cs:579
void Invoke(Task completingTask)
Definition Task.cs:562
static readonly Func< Task< Task >, Task< TResult > > Value
Definition Task.cs:17
TwoTaskWhenAnyPromise(TTask task1, TTask task2)
Definition Task.cs:892
override bool ShouldNotifyDebuggerOfWaitCompletion
Definition Task.cs:678
void Invoke(Task completedTask)
Definition Task.cs:714
Task(Action< object?> action, object? state, TaskCreationOptions creationOptions)
Definition Task.cs:1280
bool AtomicStateUpdateSlow(int newBits, int illegalBits)
Definition Task.cs:1388
void UpdateExceptionObservedStatus()
Definition Task.cs:1830
ContingentProperties EnsureContingentPropertiesInitializedUnsafe()
Definition Task.cs:1647
Task ContinueWith(Action< Task< TResult > > continuationAction, TaskContinuationOptions continuationOptions)
Definition Task.cs:278
Task(bool canceled, TResult result, TaskCreationOptions creationOptions, CancellationToken ct)
Definition Task.cs:73
static Dictionary< int, Task > s_currentActiveTasks
Definition Task.cs:962
Task ContinueWith(Action< Task< TResult > > continuationAction)
Definition Task.cs:263
static int WaitAny(Task[] tasks, int millisecondsTimeout)
Definition Task.cs:3259
bool Wait(int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:2250
ContingentProperties EnsureContingentPropertiesInitialized()
Definition Task.cs:1637
bool TrySetResult(TResult result)
Definition Task.cs:162
void AddException(object exceptionObject, bool representsCancellation)
Definition Task.cs:1745
bool AddTaskContinuationComplex(object tc, bool addBeforeOthers)
Definition Task.cs:2960
Task(Func< TResult > function)
Definition Task.cs:82
ContingentProperties m_contingentProperties
Definition Task.cs:964
ExecutionContext? CapturedContext
Definition Task.cs:1160
TaskCreationOptions Options
Definition Task.cs:981
static bool WaitAllCore(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:3079
Task(Action action)
Definition Task.cs:1250
static bool WaitAll(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:3073
Task(Func< TResult > function, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Definition Task.cs:97
static Task InternalWhenAll(Task[] tasks)
Definition Task.cs:3564
volatile object m_continuationObject
Definition Task.cs:956
static Task< Task > WhenAny(IEnumerable< Task > tasks)
Definition Task.cs:3687
TaskScheduler m_taskScheduler
Definition Task.cs:952
Task ContinueWith(Action< Task, object?> continuationAction, object? state)
Definition Task.cs:2779
void FireTaskScheduledIfNeeded(TaskScheduler ts)
Definition Task.cs:1471
void UnsafeSetContinuationForAwait(IAsyncStateMachineBox stateMachineBox, bool continueOnCapturedContext)
Definition Task.cs:2189
bool IsWaitNotificationEnabledOrNotRanToCompletion
Definition Task.cs:984
Task ContinueWith(Action< Task > continuationAction)
Definition Task.cs:2738
static uint ValidateTimeout(TimeSpan timeout, ExceptionArgument argument)
Definition Task.cs:3494
static int WaitAny(Task[] tasks, CancellationToken cancellationToken)
Definition Task.cs:3253
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
Task(TResult result)
Definition Task.cs:67
virtual void InnerInvoke()
Definition Task.cs:2118
static void CreationOptionsFromContinuationOptions(TaskContinuationOptions continuationOptions, out TaskCreationOptions creationOptions, out InternalTaskOptions internalOptions)
Definition Task.cs:2902
ManualResetEventSlim CompletedEvent
Definition Task.cs:1123
ExceptionDispatchInfo GetCancellationExceptionDispatchInfo()
Definition Task.cs:1786
Task ContinueWith(Action< Task< TResult >, object?> continuationAction, object? state, TaskContinuationOptions continuationOptions)
Definition Task.cs:319
void HandleException(Exception unhandledException)
Definition Task.cs:2130
Task(Action action, TaskCreationOptions creationOptions)
Definition Task.cs:1260
bool InternalWait(int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:2325
Task ContinueWith(Action< Task< TResult >, object?> continuationAction, object? state)
Definition Task.cs:304
ConfiguredTaskAwaitable ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:2148
static void LogFinishCompletionNotification()
Definition Task.cs:2730
void InternalCancelContinueWithInitialState()
Definition Task.cs:2477
static bool s_asyncDebuggingEnabled
Definition Task.cs:960
static int WaitAny(params Task[] tasks)
Definition Task.cs:3236
volatile int m_stateFlags
Definition Task.cs:954
Task ContinueWith(Action< Task, object > continuationAction, object state, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
Definition Task.cs:2804
string DebuggerDisplayResultDescription
Definition Task.cs:27
void DangerousSetResult(TResult result)
Definition Task.cs:181
static Task Delay(TimeSpan delay, CancellationToken cancellationToken)
Definition Task.cs:3458
Task ContinueWith(Action< Task< TResult >, object?> continuationAction, object? state, CancellationToken cancellationToken)
Definition Task.cs:309
void RunOrQueueCompletionAction(ITaskCompletionAction completionAction, bool allowInlining)
Definition Task.cs:2718
static TaskFactory< TResult > s_Factory
Definition Task.cs:22
static void WaitAll(Task[] tasks, CancellationToken cancellationToken)
Definition Task.cs:3066
Task ContinueWith(Action< Task, object?> continuationAction, object? state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Definition Task.cs:2799
bool SpinWait(int millisecondsTimeout)
Definition Task.cs:2418
static Task Delay(int millisecondsDelay)
Definition Task.cs:3463
static Task InternalCurrentIfAttached(TaskCreationOptions creationOptions)
Definition Task.cs:1628
Task ContinueWith(Action< Task< TResult >, object > continuationAction, object state, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
Definition Task.cs:329
new Task< TResult > WaitAsync(CancellationToken cancellationToken)
Definition Task.cs:231
bool Wait(int millisecondsTimeout)
Definition Task.cs:2245
static ? int CurrentId
Definition Task.cs:1009
Task(object state, TaskCreationOptions options)
Definition Task.cs:62
string DebuggerDisplayMethodDescription
Definition Task.cs:39
void RecordInternalCancellationRequest(CancellationToken tokenToRecord, object cancellationException)
Definition Task.cs:2488
Task(Action< object?> action, object? state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Definition Task.cs:1285
void AddCompletionAction(ITaskCompletionAction action, bool addBeforeOthers=false)
Definition Task.cs:2952
static Task Run(Func< Task?> function)
Definition Task.cs:3415
List< ExceptionDispatchInfo > GetExceptionDispatchInfos()
Definition Task.cs:1781
static Task< TResult[]> InternalWhenAll< TResult >(Task< TResult >[] tasks)
Definition Task.cs:3633
static new TaskFactory< TResult > Factory
Definition Task.cs:56
bool TrySetCanceled(CancellationToken tokenToRecord)
Definition Task.cs:2555
static Task Run(Func< Task?> function, CancellationToken cancellationToken)
Definition Task.cs:3420
void RunContinuations(object continuationObject)
Definition Task.cs:2581
static int WaitAny(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:3265
Task WaitAsync(TimeSpan timeout, CancellationToken cancellationToken)
Definition Task.cs:2286
Task ContinueWith(Action< Task< TResult >, object?> continuationAction, object? state, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Definition Task.cs:324
static int WaitAnyCore(Task[] tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:3270
static Delegate[] GetDelegatesFromContinuationObject(object continuationObject)
Definition Task.cs:3779
void AddExceptionsFromChildren(ContingentProperties props)
Definition Task.cs:1977
static void AddExceptionsForCompletedTask(ref List< Exception > exceptions, Task t)
Definition Task.cs:3221
Task(Func< object?, TResult > function, object? state, CancellationToken cancellationToken)
Definition Task.cs:107
void InternalRunSynchronously(TaskScheduler scheduler, bool waitForCompletion)
Definition Task.cs:1550
void NotifyDebuggerOfWaitCompletion()
Definition Task.cs:1461
void ExecuteWithThreadLocal(ref Task currentTaskSlot, Thread threadPoolThread=null)
Definition Task.cs:2046
Task ContinueWith(Action< Task< TResult >, object?> continuationAction, object? state, TaskScheduler scheduler)
Definition Task.cs:314
Task ContinueWith(Action< Task > continuationAction, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
Definition Task.cs:2763
static Task< TResult > FromResult< TResult >(TResult result)
Definition Task.cs:3311
Task ContinueWith(Action< Task, object?> continuationAction, object? state, TaskContinuationOptions continuationOptions)
Definition Task.cs:2794
static Task< Task > WhenAny(Task task1, Task task2)
Definition Task.cs:3670
bool TrySetException(object exceptionObject)
Definition Task.cs:2542
void RemoveContinuation(object continuationObject)
Definition Task.cs:3005
void SetContinuationForAwait(Action continuationAction, bool continueOnCapturedContext, bool flowExecutionContext)
Definition Task.cs:2153
TaskScheduler? ExecutingTaskScheduler
Definition Task.cs:1115
Task(Delegate valueSelector, object state, Task parent, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
Definition Task.cs:127
Task ContinueWith(Action< Task< TResult > > continuationAction, TaskScheduler scheduler)
Definition Task.cs:273
virtual Delegate[] GetDelegateContinuationsForDebugger()
Definition Task.cs:3770
void Finish(bool userDelegateExecute)
Definition Task.cs:1839
Task(Func< TResult > function, CancellationToken cancellationToken)
Definition Task.cs:87
static Task< TResult > CreateUnwrapPromise< TResult >(Task outerTask, bool lookForOce)
Definition Task.cs:3765
static Task Delay(uint millisecondsDelay, CancellationToken cancellationToken)
Definition Task.cs:3477
static bool IsCompletedMethod(int flags)
Definition Task.cs:1652
Task(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Definition Task.cs:1265
Task WaitAsync(uint millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:2291
virtual void ExecuteFromThreadPool(Thread threadPoolThread)
Definition Task.cs:2016
TResult GetResultCore(bool waitCompletionNotification)
Definition Task.cs:192
Task ContinueWith(Action< Task > continuationAction, TaskScheduler scheduler)
Definition Task.cs:2748
static bool WaitAllBlockingCore(List< Task > tasks, int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:3193
void ThrowIfExceptional(bool includeTaskCanceledExceptions)
Definition Task.cs:1796
Task(Action action, CancellationToken cancellationToken)
Definition Task.cs:1255
AggregateException GetExceptions(bool includeTaskCanceledExceptions)
Definition Task.cs:1762
bool NotifyDebuggerOfWaitCompletionIfNecessary()
Definition Task.cs:1438
void ProcessChildCompletion(Task childTask)
Definition Task.cs:1953
static Task< TResult[]> WhenAll< TResult >(IEnumerable< Task< TResult > > tasks)
Definition Task.cs:3573
Task(Func< object?, TResult > function, object? state, CancellationToken cancellationToken, TaskCreationOptions creationOptions)
Definition Task.cs:117
static Task FromException(Exception exception)
Definition Task.cs:3341
void ScheduleAndStart(bool needsProtection)
Definition Task.cs:1702
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363
static bool WaitAll(Task[] tasks, int millisecondsTimeout)
Definition Task.cs:3059
static Task GetActiveTaskFromId(int taskId)
Definition Task.cs:3831
Task ContinueWith(Action< Task > continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Definition Task.cs:2758
override void InnerInvoke()
Definition Task.cs:209
Task(Action< object?> action, object? state, CancellationToken cancellationToken)
Definition Task.cs:1275
Task ContinueWith(Action< Task, object?> continuationAction, object? state, CancellationToken cancellationToken)
Definition Task.cs:2784
bool Wait(TimeSpan timeout)
Definition Task.cs:2230
Task(Func< object?, TResult > function, object? state)
Definition Task.cs:102
static bool WaitAll(Task[] tasks, TimeSpan timeout)
Definition Task.cs:3047
static int s_taskIdCounter
Definition Task.cs:944
void NotifyParentIfPotentiallyAttachedTask()
Definition Task.cs:1944
static Task Run(Action action)
Definition Task.cs:3395
void ExecuteEntryUnsafe(Thread threadPoolThread)
Definition Task.cs:2021
new Task< TResult > WaitAsync(TimeSpan timeout, CancellationToken cancellationToken)
Definition Task.cs:241
static YieldAwaitable Yield()
Definition Task.cs:2220
static Task< Task< TResult > > WhenAny< TResult >(params Task< TResult >[] tasks)
Definition Task.cs:3732
static Task< TResult > FromException< TResult >(Exception exception)
Definition Task.cs:3352
Task(bool canceled, TaskCreationOptions creationOptions, CancellationToken ct)
Definition Task.cs:1211
TaskCreationOptions CreationOptions
Definition Task.cs:1097
static void WaitAll(params Task[] tasks)
Definition Task.cs:3040
Task(Func< TResult > function, TaskCreationOptions creationOptions)
Definition Task.cs:92
static Task< TResult > Run< TResult >(Func< TResult > function)
Definition Task.cs:3405
Task ContinueWith(Action< Task< TResult > > continuationAction, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions, TaskScheduler scheduler)
Definition Task.cs:283
static Task FromCanceled(OperationCanceledException exception)
Definition Task.cs:3381
Task(Func< object?, TResult > function, object? state, TaskCreationOptions creationOptions)
Definition Task.cs:112
virtual bool ShouldNotifyDebuggerOfWaitCompletion
Definition Task.cs:992
static ? Task InternalCurrent
Definition Task.cs:1011
TaskAwaiter GetAwaiter()
Definition Task.cs:2143
static readonly Task< VoidTaskResult > s_cachedCompleted
Definition Task.cs:966
static Task< TResult > StartNew(Task parent, Func< object, TResult > function, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
Definition Task.cs:147
static TaskCreationOptions OptionsMethod(int flags)
Definition Task.cs:1369
bool AddTaskContinuation(object tc, bool addBeforeOthers)
Definition Task.cs:2992
static Task InternalStartNew(Task creatingTask, Delegate action, object state, CancellationToken cancellationToken, TaskScheduler scheduler, TaskCreationOptions options, InternalTaskOptions internalOptions)
Definition Task.cs:1602
void Start(TaskScheduler scheduler)
Definition Task.cs:1509
Task ContinueWith(Action< Task, object?> continuationAction, object? state, TaskScheduler scheduler)
Definition Task.cs:2789
bool TrySetCanceled(CancellationToken tokenToRecord, object cancellationException)
Definition Task.cs:2560
bool InternalWaitCore(int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:2330
void TaskConstructorCore(Delegate action, object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
Definition Task.cs:1304
static void AddToList< T >(T item, ref List< T > list, int initSize)
Definition Task.cs:3183
static Task CompletedTask
Definition Task.cs:1120
void SetCancellationAcknowledged()
Definition Task.cs:2521
void AddException(object exceptionObject)
Definition Task.cs:1740
static Task< TResult > StartNew(Task parent, Func< TResult > function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
Definition Task.cs:132
Task(Delegate action, object state, Task parent, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
Definition Task.cs:1290
void RecordInternalCancellationRequest()
Definition Task.cs:2483
static readonly object s_taskCompletionSentinel
Definition Task.cs:958
Task< TResult > ContinueWith< TResult >(Func< Task, TResult > continuationFunction)
Definition Task.cs:2820
static Task Delay(TimeSpan delay)
Definition Task.cs:3453
void RunSynchronously(TaskScheduler scheduler)
Definition Task.cs:1541
bool AtomicStateUpdate(int newBits, int illegalBits)
Definition Task.cs:1374
virtual void Dispose(bool disposing)
Definition Task.cs:1672
Task(object state, TaskCreationOptions creationOptions, bool promiseStyle)
Definition Task.cs:1233
static Task t_currentTask
Definition Task.cs:942
Task< TResult > WaitAsync(uint millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:246
void ContinueWithCore(Task continuationTask, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions options)
Definition Task.cs:2920
static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
Definition Task.cs:1806
Task ContinueWith(Action< Task > continuationAction, CancellationToken cancellationToken)
Definition Task.cs:2743
static int WaitAny(Task[] tasks, TimeSpan timeout)
Definition Task.cs:3242
static readonly Task< TResult > s_defaultResultTask
Definition Task.cs:20
static Task WhenAll(params Task[] tasks)
Definition Task.cs:3540
void ExecuteEntryCancellationRequestedOrCanceled()
Definition Task.cs:2034
Task ContinueWith(Action< Task< TResult > > continuationAction, TaskScheduler scheduler, CancellationToken cancellationToken, TaskContinuationOptions continuationOptions)
Definition Task.cs:288
Task WaitAsync(TimeSpan timeout)
Definition Task.cs:2281
new TaskAwaiter< TResult > GetAwaiter()
Definition Task.cs:221
void SetNotificationForWaitCompletion(bool enabled)
Definition Task.cs:1426
static Task< Task > WhenAny(params Task[] tasks)
Definition Task.cs:3642
Task(Action< object?> action, object? state)
Definition Task.cs:1270
static Task Run(Action action, CancellationToken cancellationToken)
Definition Task.cs:3400
static Task< TResult > FromCanceled< TResult >(CancellationToken cancellationToken)
Definition Task.cs:3372
Task ContinueWith(Action< Task > continuationAction, TaskContinuationOptions continuationOptions)
Definition Task.cs:2753
new Task< TResult > WaitAsync(TimeSpan timeout)
Definition Task.cs:236
bool AtomicStateUpdate(int newBits, int illegalBits, ref int oldFlags)
Definition Task.cs:1407
static Task Delay(int millisecondsDelay, CancellationToken cancellationToken)
Definition Task.cs:3468
void FinishSlow(bool userDelegateExecute)
Definition Task.cs:1851
static Task WhenAll(IEnumerable< Task > tasks)
Definition Task.cs:3504
Task WaitAsync(CancellationToken cancellationToken)
Definition Task.cs:2276
static bool AddToActiveTasks(Task task)
Definition Task.cs:1186
void Wait(CancellationToken cancellationToken)
Definition Task.cs:2240
Task ContinueWith(Action< Task< TResult > > continuationAction, CancellationToken cancellationToken)
Definition Task.cs:268
static void RemoveFromActiveTasks(Task task)
Definition Task.cs:1197
static bool AnyTaskRequiresNotifyDebuggerOfWaitCompletion(Task[] tasks)
Definition Task.cs:1448
static readonly ContextCallback s_ecCallback
Definition Task.cs:968
Task(Func< TResult > valueSelector, Task parent, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler)
Definition Task.cs:122
Task< TNewResult > ContinueWith< TNewResult >(Func< Task< TResult >, TNewResult > continuationFunction)
Definition Task.cs:345
bool SpinThenBlockingWait(int millisecondsTimeout, CancellationToken cancellationToken)
Definition Task.cs:2361
void AssignCancellationToken(CancellationToken cancellationToken, Task antecedent, TaskContinuation continuation)
Definition Task.cs:1330
static readonly TplEventSource Log
static Guid CreateGuidForTaskID(int taskID)
static bool NotifyThreadBlocked()
static bool QueueUserWorkItem(WaitCallback callBack)
static void NotifyThreadUnblocked()
static void UnsafeQueueUserWorkItemInternal(object callBack, bool preferLocal)
static bool Read(ref bool location)
Definition Volatile.cs:67
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowObjectDisposedException(ExceptionResource resource)
static void ThrowInvalidOperationException()
static void ThrowAggregateException(List< Exception > exceptions)
static void ThrowArgumentNullException(string name)
static void ThrowArgumentException(ExceptionResource resource)
delegate void ContextCallback(object? state)
CancellationTokenRegistration UnsafeRegister(Action< object?> callback, object? state)
static readonly int SpinCountforSpinBeforeWait
Definition SpinWait.cs:5