Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TaskAwaiter.cs
Go to the documentation of this file.
7
9
10public readonly struct TaskAwaiter : ICriticalNotifyCompletion, INotifyCompletion, ITaskAwaiter
11{
12 internal readonly Task m_task;
13
15
17 {
18 m_task = task;
19 }
20
25
30
32 public void GetResult()
33 {
35 }
36
38 internal static void ValidateEnd(Task task)
39 {
40 if (task.IsWaitNotificationEnabledOrNotRanToCompletion)
41 {
43 }
44 }
45
48 {
49 if (!task.IsCompleted)
50 {
51 bool flag = task.InternalWait(-1, default(CancellationToken));
52 }
53 task.NotifyDebuggerOfWaitCompletionIfNecessary();
54 if (!task.IsCompletedSuccessfully)
55 {
57 }
58 }
59
61 private static void ThrowForNonSuccess(Task task)
62 {
63 switch (task.Status)
64 {
65 case TaskStatus.Canceled:
66 task.GetCancellationExceptionDispatchInfo()?.Throw();
67 throw new TaskCanceledException(task);
68 case TaskStatus.Faulted:
69 {
70 List<ExceptionDispatchInfo> exceptionDispatchInfos = task.GetExceptionDispatchInfos();
72 {
73 exceptionDispatchInfos[0].Throw();
74 break;
75 }
76 throw task.Exception;
77 }
78 }
79 }
80
82 {
83 if (continuation == null)
84 {
85 throw new ArgumentNullException("continuation");
86 }
88 {
90 }
92 }
93
95 {
97 {
98 task.SetContinuationForAwait(OutputWaitEtwEvents(task, stateMachineBox.MoveNextAction), continueOnCapturedContext, flowExecutionContext: false);
99 }
100 else
101 {
102 task.UnsafeSetContinuationForAwait(stateMachineBox, continueOnCapturedContext);
103 }
104 }
105
106 private static Action OutputWaitEtwEvents(Task task, Action continuation)
107 {
109 {
111 }
113 if (log.IsEnabled())
114 {
117 log.TaskWaitBegin(internalCurrent?.m_taskScheduler.Id ?? TaskScheduler.Default.Id, internalCurrent?.Id ?? 0, task.Id, TplEventSource.TaskWaitBehavior.Asynchronous, task2?.Id ?? 0);
118 }
120 {
122 {
123 Task.RemoveFromActiveTasks(innerTask);
124 }
127 bool flag = log2.IsEnabled();
128 if (flag)
129 {
131 log2.TaskWaitEnd(internalCurrent2?.m_taskScheduler.Id ?? TaskScheduler.Default.Id, internalCurrent2?.Id ?? 0, innerTask.Id);
132 if (log2.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)1024) != 0)
133 {
135 }
136 }
138 if (flag)
139 {
140 log2.TaskWaitContinuationComplete(innerTask.Id);
141 if (log2.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)1024) != 0)
142 {
144 }
145 }
146 }, task);
147 }
148}
static void SetCurrentThreadActivityId(Guid activityId)
static Action CreateContinuationWrapper(Action continuation, Action< Action, Task > invokeAction, Task innerTask)
static bool s_asyncDebuggingEnabled
Definition Task.cs:960
static ? Task InternalCurrent
Definition Task.cs:1011
static bool AddToActiveTasks(Task task)
Definition Task.cs:1186
static readonly TplEventSource Log
static Guid CreateGuidForTaskID(int taskID)
void OnCompleted(Action continuation)
static Action OutputWaitEtwEvents(Task task, Action continuation)
static void HandleNonSuccessAndDebuggerNotification(Task task)
static void OnCompletedInternal(Task task, Action continuation, bool continueOnCapturedContext, bool flowExecutionContext)
void UnsafeOnCompleted(Action continuation)
static void UnsafeOnCompletedInternal(Task task, IAsyncStateMachineBox stateMachineBox, bool continueOnCapturedContext)