@@ -186,6 +186,8 @@ internal unsafe ref struct AsyncDispatcherInfo
186186 [ FieldOffset ( 8 ) ]
187187#endif
188188 // The runtime async Task being dispatched.
189+ // This is used by debuggers in the case of nested dispatcher info (multiple runtime-async Tasks on the same thread)
190+ // to match an inflight Task to the corresponding Continuation chain.
189191 public Task Task ;
190192
191193 // Information about current task dispatching, to be used for async
@@ -500,9 +502,10 @@ private unsafe void DispatchContinuations()
500502 asyncDispatcherInfo . NextContinuation = nextContinuation ;
501503
502504 ref byte resultLoc = ref nextContinuation != null ? ref nextContinuation . GetResultStorageOrNull ( ) : ref GetResultStorage ( ) ;
505+ RuntimeAsyncContinuationDebugInfo ? debugInfo = null ;
503506 if ( Task . s_asyncDebuggingEnabled )
504507 {
505- RuntimeAsyncContinuationDebugInfo debugInfo = Task . GetRuntimeAsyncContinuationDebugInfo ( curContinuation , out RuntimeAsyncContinuationDebugInfo ? debugInfoVal ) ? debugInfoVal : new RuntimeAsyncContinuationDebugInfo ( Stopwatch . GetTimestamp ( ) ) ;
508+ debugInfo = Task . GetRuntimeAsyncContinuationDebugInfo ( curContinuation , out RuntimeAsyncContinuationDebugInfo ? debugInfoVal ) ? debugInfoVal : new RuntimeAsyncContinuationDebugInfo ( Stopwatch . GetTimestamp ( ) ) ;
506509 // we have dequeued curContinuation; update task tick info so that we can track its start time from a debugger
507510 Task . UpdateRuntimeAsyncTaskTicks ( this , debugInfo . TickCount ) ;
508511 }
@@ -515,7 +518,7 @@ private unsafe void DispatchContinuations()
515518 {
516519 // we have a new Continuation that belongs to the same logical invocation as the previous; propagate debug info from previous continuation
517520 if ( Task . s_asyncDebuggingEnabled )
518- Task . UpdateRuntimeAsyncContinuationDebugInfo ( newContinuation , debugInfo ) ;
521+ Task . UpdateRuntimeAsyncContinuationDebugInfo ( newContinuation , debugInfo ! ) ;
519522 newContinuation . Next = nextContinuation ;
520523 HandleSuspended ( ) ;
521524 contexts . Pop ( ) ;
@@ -551,7 +554,7 @@ private unsafe void DispatchContinuations()
551554
552555 if ( asyncDispatcherInfo . NextContinuation == null )
553556 {
554- if ( TplEventSource . Log . IsEnabled ( ) )
557+ if ( isTplEnabled )
555558 {
556559 TplEventSource . Log . TraceOperationEnd ( this . Id , AsyncCausalityStatus . Completed ) ;
557560 }
@@ -595,8 +598,8 @@ private unsafe void DispatchContinuations()
595598 {
596599 if ( continuation == null || ( continuation . Flags & ContinuationFlags . HasException ) != 0 )
597600 return continuation ;
598-
599- RemoveRuntimeAsyncContinuationTicks ( continuation ) ;
601+ if ( Task . s_asyncDebuggingEnabled )
602+ Task . RemoveRuntimeAsyncContinuationTicks ( continuation ) ;
600603 continuation = continuation . Next ;
601604 }
602605 }
0 commit comments