Repository: dotnet/runtime
File: src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs (C#)

Code before:
                        vtsNotifier.OnCompleted(s_runContinuationAction, this, configFlags);
                    }
                    else
                    {
                        Debug.Assert(notifier != null);
                        notifier.OnCompleted(GetContinuationAction());
                    }
                }
                catch (Exception ex)
                {
                    Task.ThrowAsync(ex, targetContext: null);
                }
            }

            private unsafe void DispatchContinuations()
            {
                ExecutionAndSyncBlockStore contexts = default;
                contexts.Push();

                AsyncDispatcherInfo asyncDispatcherInfo;
                asyncDispatcherInfo.Next = AsyncDispatcherInfo.t_current;
                asyncDispatcherInfo.NextContinuation = MoveContinuationState();
                AsyncDispatcherInfo.t_current = &asyncDispatcherInfo;
                asyncDispatcherInfo.Task = this;

                if (TplEventSource.Log.IsEnabled())
                {
                    TplEventSource.Log.TraceSynchronousWorkBegin(this.Id, CausalitySynchronousWork.Execution);
                }

                while (true)
                {
                    Debug.Assert(asyncDispatcherInfo.NextContinuation != null);
                    try
                    {
                        Continuation curContinuation = asyncDispatcherInfo.NextContinuation;
                        Continuation? nextContinuation = curContinuation.Next;
                        asyncDispatcherInfo.NextContinuation = nextContinuation;

                        ref byte resultLoc = ref nextContinuation != null ? ref nextContinuation.GetResultStorageOrNull() : ref GetResultStorage();
                        long tickCount = Task.GetRuntimeAsyncContinuationTicks(curContinuation, out long tickCountVal) ? tickCountVal : Environment.TickCount64;
                        Task.UpdateRuntimeAsyncTaskTicks(this, tickCount);
                        Continuation? newContinuation = curContinuation.ResumeInfo->Resume(curContinuation, ref resultLoc);

                        Task.RemoveRuntimeAsyncContinuationTicks(curContinuation);

                        if (newContinuation != null)
                        {
                            Task.UpdateRuntimeAsyncContinuationTicks(newContinuation, tickCount);
                            newContinuation.Next = nextContinuation;
                            HandleSuspended();

Review comment (suggestion):
We should follow the pattern used at other sites TraceSyncWorkBegin is called where IsEnabled() is assigned to a boolean and then we use the same value to condition both the Begin and the End events.

Code after:
                        // Clear continuation flags, so that continuation runs transparently
                        nextUserContinuation.Flags &= ~continueFlags;
                        vtsNotifier.OnCompleted(s_runContinuationAction, this, configFlags);
                    }
                    else
                    {
                        Debug.Assert(notifier != null);
                        notifier.OnCompleted(GetContinuationAction());
                    }
                }
                catch (Exception ex)
                {
                    if (Task.s_asyncDebuggingEnabled)
                    {
                        Task.RemoveFromActiveTasks(this);
                        Task.RemoveRuntimeAsyncTaskTimestamp(this);
                        Continuation? nextCont = headContinuation;
                        while (nextCont != null)
                        {
                            Task.RemoveRuntimeAsyncContinuationTimestamp(nextCont);
                            nextCont = nextCont.Next;
                        }
                    }

                    Task.ThrowAsync(ex, targetContext: null);
                }
            }

#pragma warning disable CA1822 // Mark members as static
            [MethodImpl(MethodImplOptions.NoOptimization)]
            public void NotifyDebuggerOfRuntimeAsyncState()
            {
            }
#pragma warning restore CA1822

            [StackTraceHidden]
            private unsafe void DispatchContinuations()
            {
                ExecutionAndSyncBlockStore contexts = default;
                contexts.Push();

                AsyncDispatcherInfo asyncDispatcherInfo;
                asyncDispatcherInfo.Next = AsyncDispatcherInfo.t_current;
                asyncDispatcherInfo.NextContinuation = MoveContinuationState();
                asyncDispatcherInfo.CurrentTask = this;
                AsyncDispatcherInfo.t_current = &asyncDispatcherInfo;
                bool isTplEnabled = TplEventSource.Log.IsEnabled();

                if (isTplEnabled)
                {
                    TplEventSource.Log.TraceSynchronousWorkBegin(this.Id, CausalitySynchronousWork.Execution);