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

Code before:
                state.ValueTaskSourceNotifier = null;
                state.TaskNotifier = null;
                state.ExecutionContext = null;
                state.SynchronizationContext = null;

                Continuation sentinelContinuation = state.SentinelContinuation!;
                Continuation headContinuation = sentinelContinuation.Next!;
                sentinelContinuation.Next = null;

                // Head continuation should be the result of async call to AwaitAwaiter or UnsafeAwaitAwaiter.
                // These never have special continuation context handling.
                const ContinuationFlags continueFlags =
                    ContinuationFlags.ContinueOnCapturedSynchronizationContext |
                    ContinuationFlags.ContinueOnThreadPool |
                    ContinuationFlags.ContinueOnCapturedTaskScheduler;

                Debug.Assert((headContinuation.Flags & continueFlags) == 0);

                SetContinuationState(headContinuation);

                Continuation? nc = headContinuation;
                if (Task.s_asyncDebuggingEnabled)
                {
                    while (nc != null)
                    {
                        // On suspension we set tick info for all continuations that have not yet had it set.
                        Task.SetRuntimeAsyncContinuationTickCount(nc, Stopwatch.GetTimestamp());
                        nc = nc.Next;
                    }
                }

                try
                {
                    if (critNotifier != null)
                    {
                        critNotifier.UnsafeOnCompleted(GetContinuationAction());
                    }
                    else if (taskNotifier != null)
                    {
                        // Runtime async callable wrapper for task returning
                        // method. This implements the context transparent
                        // forwarding and makes these wrappers minimal cost.
                        if (!taskNotifier.TryAddCompletionAction(this))
                        {
                            ThreadPool.UnsafeQueueUserWorkItemInternal(this, preferLocal: true);
                        }
                    }
                    else if (vtsNotifier != null)
                    {
                        // The awaiter must inform the ValueTaskSource on whether the continuation
                        // wants to run on a context, although the source may decide to ignore the suggestion.

Review comment (suggestion):
```suggestion
                        // On suspension we set timestamp for all continuations that have not yet had it set.
```

Code after:
                const ContinuationFlags continueFlags =
                    ContinuationFlags.ContinueOnCapturedSynchronizationContext |
                    ContinuationFlags.ContinueOnThreadPool |
                    ContinuationFlags.ContinueOnCapturedTaskScheduler;

                Debug.Assert((headContinuation.Flags & continueFlags) == 0);

                SetContinuationState(headContinuation);

                Continuation? nc = headContinuation;
                if (Task.s_asyncDebuggingEnabled)
                {
                    long timestamp = Stopwatch.GetTimestamp();
                    while (nc != null)
                    {
                        // On suspension we set timestamp for all continuations that have not yet had it set.
                        Task.SetRuntimeAsyncContinuationTimestamp(nc, timestamp);
                        nc = nc.Next;
                    }
                }

                try
                {
                    if (critNotifier != null)
                    {
                        critNotifier.UnsafeOnCompleted(GetContinuationAction());
                    }
                    else if (taskNotifier != null)
                    {
                        // Runtime async callable wrapper for task returning
                        // method. This implements the context transparent
                        // forwarding and makes these wrappers minimal cost.
                        if (!taskNotifier.TryAddCompletionAction(this))
                        {
                            ThreadPool.UnsafeQueueUserWorkItemInternal(this, preferLocal: true);
                        }
                    }
                    else if (vtsNotifier != null)
                    {
                        // The awaiter must inform the ValueTaskSource on whether the continuation
                        // wants to run on a context, although the source may decide to ignore the suggestion.
                        // Since the behavior of the source takes precedence, we clear the context flags of
                        // the awaiting continuation (so it will run transparently on what the source decides)
                        // and then tell the source if the awaiting frame prefers to continue on a context.
                        // The reason why we do it here and not when the notifier is created is because
                        // the continuation chain builds from the innermost frame out and at the time when the
                        // notifier is created we do not know yet if the caller wants to continue on a context.
                        ValueTaskSourceOnCompletedFlags configFlags = ValueTaskSourceOnCompletedFlags.None;

                        // Skip to a nontransparent/user continuation. Such continuaton must exist.
                        // Since we see a VTS notifier, something was directly or indirectly