/// <summary> /// Outputs a WaitBegin ETW event, and augments the continuation action to output a WaitEnd ETW event. /// </summary> /// <param name="task">The task being awaited.</param> /// <param name="continuation">The action to invoke when the await operation completes.</param> /// <returns>The action to use as the actual continuation.</returns> private static Action OutputWaitEtwEvents(Task task, Action continuation) { Debug.Assert(task != null, "Need a task to wait on"); Debug.Assert(continuation != null, "Need a continuation to invoke when the wait completes"); if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } TplEventSource log = TplEventSource.Log; if (log.IsEnabled()) { // ETW event for Task Wait Begin Task?currentTaskAtBegin = Task.InternalCurrent; // If this task's continuation is another task, get it. Task?continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); log.TaskWaitBegin( currentTaskAtBegin != null ? currentTaskAtBegin.m_taskScheduler !.Id : TaskScheduler.Default.Id, currentTaskAtBegin != null ? currentTaskAtBegin.Id : 0, task.Id, TplEventSource.TaskWaitBehavior.Asynchronous, continuationTask != null ? continuationTask.Id : 0); } // Create a continuation action that outputs the end event and then invokes the user // provided delegate. This incurs the allocations for the closure/delegate, but only if the event // is enabled, and in doing so it allows us to pass the awaited task's information into the end event // in a purely pay-for-play manner (the alternatively would be to increase the size of TaskAwaiter // just for this ETW purpose, not pay-for-play, since GetResult would need to know whether a real yield occurred). return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, static (innerContinuation, innerTask) =>
/// <summary> /// Outputs a WaitBegin ETW event, and augments the continuation action to output a WaitEnd ETW event. /// </summary> /// <param name="task">The task being awaited.</param> /// <param name="continuation">The action to invoke when the await operation completes.</param> /// <returns>The action to use as the actual continuation.</returns> private static Action OutputWaitEtwEvents(Task task, Action continuation) { Debug.Assert(task != null, "Need a task to wait on"); Debug.Assert(continuation != null, "Need a continuation to invoke when the wait completes"); if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } TplEventSource log = TplEventSource.Log; if (log.IsEnabled()) { // ETW event for Task Wait Begin Task?currentTaskAtBegin = Task.InternalCurrent; // If this task's continuation is another task, get it. Task?continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); log.TaskWaitBegin( currentTaskAtBegin != null ? currentTaskAtBegin.m_taskScheduler !.Id : TaskScheduler.Default.Id, currentTaskAtBegin != null ? currentTaskAtBegin.Id : 0, task.Id, TplEventSource.TaskWaitBehavior.Asynchronous, continuationTask != null ? continuationTask.Id : 0); } // Create a continuation action that outputs the end event and then invokes the user // provided delegate. This incurs the allocations for the closure/delegate, but only if the event // is enabled, and in doing so it allows us to pass the awaited task's information into the end event // in a purely pay-for-play manner (the alternatively would be to increase the size of TaskAwaiter // just for this ETW purpose, not pay-for-play, since GetResult would need to know whether a real yield occurred). return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (innerContinuation, innerTask) => { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(innerTask); } TplEventSource innerEtwLog = TplEventSource.Log; // ETW event for Task Wait End. Guid prevActivityId = default; bool bEtwLogEnabled = innerEtwLog.IsEnabled(); if (bEtwLogEnabled) { Task?currentTaskAtEnd = Task.InternalCurrent; innerEtwLog.TaskWaitEnd( currentTaskAtEnd != null ? currentTaskAtEnd.m_taskScheduler !.Id : TaskScheduler.Default.Id, currentTaskAtEnd != null ? currentTaskAtEnd.Id : 0, innerTask.Id); // Ensure the continuation runs under the activity ID of the task that completed for the // case the antecedent is a promise (in the other cases this is already the case). if (innerEtwLog.TasksSetActivityIds && (innerTask.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0) { EventSource.SetCurrentThreadActivityId(TplEventSource.CreateGuidForTaskID(innerTask.Id), out prevActivityId); } }
// Token: 0x06006FC9 RID: 28617 RVA: 0x00180349 File Offset: 0x0017E549 internal ContinuationWrapper(Action continuation, Action invokeAction, Task innerTask) { if (innerTask == null) { innerTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); } this.m_continuation = continuation; this.m_innerTask = innerTask; this.m_invokeAction = invokeAction; }
private static Action OutputWaitEtwEvents(Task task, Action continuation) { if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } TplEtwProvider etwLog = TplEtwProvider.Log; if (etwLog.IsEnabled()) { Task internalCurrent = Task.InternalCurrent; Task continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); etwLog.TaskWaitBegin(internalCurrent != null ? internalCurrent.m_taskScheduler.Id : TaskScheduler.Default.Id, internalCurrent != null ? internalCurrent.Id : 0, task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, continuationTask != null ? continuationTask.Id : 0, Thread.GetDomainID()); } return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (Action)(() => { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(task.Id); } Guid oldActivityThatWillContinue = new Guid(); int num = etwLog.IsEnabled() ? 1 : 0; if (num != 0) { Task internalCurrent = Task.InternalCurrent; etwLog.TaskWaitEnd(internalCurrent != null ? internalCurrent.m_taskScheduler.Id : TaskScheduler.Default.Id, internalCurrent != null ? internalCurrent.Id : 0, task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)1024) != TaskCreationOptions.None) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(task.Id), out oldActivityThatWillContinue); } } continuation(); if (num == 0) { return; } etwLog.TaskWaitContinuationComplete(task.Id); if (!etwLog.TasksSetActivityIds || (task.Options & (TaskCreationOptions)1024) == TaskCreationOptions.None) { return; } EventSource.SetCurrentThreadActivityId(oldActivityThatWillContinue); }), (Task)null)); }
// Token: 0x06005D28 RID: 23848 RVA: 0x00146878 File Offset: 0x00144A78 private static Action OutputWaitEtwEvents(Task task, Action continuation) { if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } TplEtwProvider etwLog = TplEtwProvider.Log; if (etwLog.IsEnabled()) { Task internalCurrent = Task.InternalCurrent; Task task2 = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); etwLog.TaskWaitBegin((internalCurrent != null) ? internalCurrent.m_taskScheduler.Id : TaskScheduler.Default.Id, (internalCurrent != null) ? internalCurrent.Id : 0, task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, (task2 != null) ? task2.Id : 0, Thread.GetDomainID()); } return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, delegate { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(task.Id); } Guid currentThreadActivityId = default(Guid); bool flag = etwLog.IsEnabled(); if (flag) { Task internalCurrent2 = Task.InternalCurrent; etwLog.TaskWaitEnd((internalCurrent2 != null) ? internalCurrent2.m_taskScheduler.Id : TaskScheduler.Default.Id, (internalCurrent2 != null) ? internalCurrent2.Id : 0, task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)1024) != TaskCreationOptions.None) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(task.Id), out currentThreadActivityId); } } continuation(); if (flag) { etwLog.TaskWaitContinuationComplete(task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)1024) != TaskCreationOptions.None) { EventSource.SetCurrentThreadActivityId(currentThreadActivityId); } } }, null)); }
/// <summary> /// Outputs a WaitBegin ETW event, and augments the continuation action to output a WaitEnd ETW event. /// </summary> /// <param name="task">The task being awaited.</param> /// <param name="continuation">The action to invoke when the await operation completes.</param> /// <returns>The action to use as the actual continuation.</returns> private static Action OutputWaitEtwEvents(Task task, Action continuation) { Contract.Requires(task != null, "Need a task to wait on"); Contract.Requires(continuation != null, "Need a continuation to invoke when the wait completes"); if (Task.s_asyncDebuggingEnabled) { Task.AddToActiveTasks(task); } #if !MONO var etwLog = TplEtwProvider.Log; if (etwLog.IsEnabled()) { // ETW event for Task Wait Begin var currentTaskAtBegin = Task.InternalCurrent; // If this task's continuation is another task, get it. var continuationTask = AsyncMethodBuilderCore.TryGetContinuationTask(continuation); etwLog.TaskWaitBegin( (currentTaskAtBegin != null ? currentTaskAtBegin.m_taskScheduler.Id : TaskScheduler.Default.Id), (currentTaskAtBegin != null ? currentTaskAtBegin.Id : 0), task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous, (continuationTask != null ? continuationTask.Id : 0), System.Threading.Thread.GetDomainID()); } #endif // Create a continuation action that outputs the end event and then invokes the user // provided delegate. This incurs the allocations for the closure/delegate, but only if the event // is enabled, and in doing so it allows us to pass the awaited task's information into the end event // in a purely pay-for-play manner (the alternatively would be to increase the size of TaskAwaiter // just for this ETW purpose, not pay-for-play, since GetResult would need to know whether a real yield occurred). return(AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, () => { if (Task.s_asyncDebuggingEnabled) { Task.RemoveFromActiveTasks(task.Id); } #if !MONO // ETW event for Task Wait End. Guid prevActivityId = new Guid(); bool bEtwLogEnabled = etwLog.IsEnabled(); if (bEtwLogEnabled) { var currentTaskAtEnd = Task.InternalCurrent; etwLog.TaskWaitEnd( (currentTaskAtEnd != null ? currentTaskAtEnd.m_taskScheduler.Id : TaskScheduler.Default.Id), (currentTaskAtEnd != null ? currentTaskAtEnd.Id : 0), task.Id); // Ensure the continuation runs under the activity ID of the task that completed for the // case the antecendent is a promise (in the other cases this is already the case). if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0) { EventSource.SetCurrentThreadActivityId(TplEtwProvider.CreateGuidForTaskID(task.Id), out prevActivityId); } } #endif // Invoke the original continuation provided to OnCompleted. continuation(); #if !MONO if (bEtwLogEnabled) { etwLog.TaskWaitContinuationComplete(task.Id); if (etwLog.TasksSetActivityIds && (task.Options & (TaskCreationOptions)InternalTaskOptions.PromiseTask) != 0) { EventSource.SetCurrentThreadActivityId(prevActivityId); } } #endif })); }