12 [__DynamicallyInvokable]
13 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
16 private readonly
Task m_task;
22 [__DynamicallyInvokable]
23 public bool IsCompleted
25 [__DynamicallyInvokable]
42 [SecuritySafeCritical]
43 [__DynamicallyInvokable]
46 OnCompletedInternal(m_task, continuation, continueOnCapturedContext:
true, flowExecutionContext:
true);
55 [__DynamicallyInvokable]
58 OnCompletedInternal(m_task, continuation, continueOnCapturedContext:
true, flowExecutionContext:
false);
65 [__DynamicallyInvokable]
71 internal static void ValidateEnd(
Task task)
73 if (task.IsWaitNotificationEnabledOrNotRanToCompletion)
75 HandleNonSuccessAndDebuggerNotification(task);
79 private static void HandleNonSuccessAndDebuggerNotification(
Task task)
85 task.NotifyDebuggerOfWaitCompletionIfNecessary();
86 if (!task.IsRanToCompletion)
88 ThrowForNonSuccess(task);
92 private static void ThrowForNonSuccess(
Task task)
97 task.GetCancellationExceptionDispatchInfo()?.
Throw();
102 if (exceptionDispatchInfos.
Count > 0)
104 exceptionDispatchInfos[0].Throw();
114 internal static void OnCompletedInternal(
Task task,
Action continuation,
bool continueOnCapturedContext,
bool flowExecutionContext)
116 if (continuation ==
null)
118 throw new ArgumentNullException(
"continuation");
120 StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
121 if (TplEtwProvider.Log.IsEnabled() ||
Task.s_asyncDebuggingEnabled)
123 continuation = OutputWaitEtwEvents(task, continuation);
125 task.SetContinuationForAwait(continuation, continueOnCapturedContext, flowExecutionContext, ref stackMark);
130 if (
Task.s_asyncDebuggingEnabled)
132 Task.AddToActiveTasks(task);
134 TplEtwProvider etwLog = TplEtwProvider.Log;
135 if (etwLog.IsEnabled())
137 Task internalCurrent =
Task.InternalCurrent;
138 Task task2 = AsyncMethodBuilderCore.TryGetContinuationTask(continuation);
139 etwLog.TaskWaitBegin(internalCurrent?.m_taskScheduler.Id ??
TaskScheduler.
Default.
Id, internalCurrent?.Id ?? 0, task.
Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, task2?.Id ?? 0,
Thread.
GetDomainID());
141 return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, delegate
143 if (
Task.s_asyncDebuggingEnabled)
145 Task.RemoveFromActiveTasks(task.Id);
147 Guid oldActivityThatWillContinue =
default(Guid);
148 bool flag = etwLog.IsEnabled();
151 Task internalCurrent2 =
Task.InternalCurrent;
152 etwLog.TaskWaitEnd(internalCurrent2?.m_taskScheduler.Id ??
TaskScheduler.
Default.
Id, internalCurrent2?.Id ?? 0, task.
Id);
161 etwLog.TaskWaitContinuationComplete(task.
Id);
172 [__DynamicallyInvokable]
173 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
182 [__DynamicallyInvokable]
185 [__DynamicallyInvokable]
202 [SecuritySafeCritical]
203 [__DynamicallyInvokable]
206 TaskAwaiter.OnCompletedInternal(m_task, continuation, continueOnCapturedContext:
true, flowExecutionContext:
true);
215 [__DynamicallyInvokable]
218 TaskAwaiter.OnCompletedInternal(m_task, continuation, continueOnCapturedContext:
true, flowExecutionContext:
false);
226 [__DynamicallyInvokable]
230 return m_task.ResultOnSuccess;
TResult GetResult()
Ends the wait for the completion of the asynchronous task.
Represents an operation that schedules continuations when it completes.
Propagates notification that operations should be canceled.
Provides the base class for a generic read-only collection.
void Throw()
Throws the exception that is represented by the current T:System.Runtime.ExceptionServices....
TaskStatus Status
Gets the T:System.Threading.Tasks.TaskStatus of this task.
void UnsafeOnCompleted(Action continuation)
Schedules the continuation action for the asynchronous task that is associated with this awaiter.
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.
int Count
Gets the number of elements contained in the T:System.Collections.ObjectModel.ReadOnlyCollection`1 in...
delegate void Action()
Encapsulates a method that has no parameters and does not return a value.
TaskCreationOptions
Specifies flags that control optional behavior for the creation and execution of tasks.
static TaskScheduler Default
Gets the default T:System.Threading.Tasks.TaskScheduler instance that is provided by the ....
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides an object that waits for the completion of an asynchronous task.
bool IsCompleted
Gets a value that indicates whether the asynchronous task has completed.
int Id
Gets the unique ID for this T:System.Threading.Tasks.TaskScheduler.
bool IsCompleted
Gets whether this T:System.Threading.Tasks.Task has completed.
static void SetCurrentThreadActivityId(Guid activityId)
[Supported in the .NET Framework 4.5.1 and later versions] Sets the activity ID on the current thread...
Provides the ability to create events for event tracing for Windows (ETW).
void GetResult()
Ends the wait for the completion of the asynchronous task.
MethodImplOptions
Defines the details of how a method is implemented.
int Id
Gets an ID for this T:System.Threading.Tasks.Task instance.
AggregateException Exception
Gets the T:System.AggregateException that caused the T:System.Threading.Tasks.Task to end prematurely...
static int GetDomainID()
Returns a unique application domain identifier.
void OnCompleted(Action continuation)
Sets the action to perform when the T:System.Runtime.CompilerServices.TaskAwaiter object stops waitin...
Represents an awaiter that schedules continuations when an await operation completes.
Represents an asynchronous operation that can return a value.
Represents an exception used to communicate task cancellation.
Creates and controls a thread, sets its priority, and gets its status.