@@ -51,7 +51,7 @@ protected WaitForHelper(
5151 this . completeChecker = completeChecker ?? throw new ArgumentNullException ( nameof ( completeChecker ) ) ;
5252
5353 logger = renderedFragment . Services . CreateLogger < WaitForHelper < T > > ( ) ;
54- checkPassedCompletionSource = new TaskCompletionSource < T > ( ) ;
54+ checkPassedCompletionSource = new TaskCompletionSource < T > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
5555 timer = new Timer ( _ =>
5656 {
5757 logger . LogWaiterTimedOut ( renderedFragment . ComponentId ) ;
@@ -121,17 +121,12 @@ private Task<T> CreateWaitTask(IRenderedFragmentBase renderedFragment)
121121
122122 // Two to failure conditions, that the renderer captures an unhandled
123123 // exception from a component or itself, or that the timeout is reached,
124- // are executed on the renderes scheduler, to ensure that OnAfterRender
124+ // are executed on the renderers scheduler, to ensure that OnAfterRender
125125 // and the continuations does not happen at the same time.
126- var failureTask = renderer . Dispatcher . InvokeAsync ( ( ) =>
126+ var failureTask = renderer . Dispatcher . InvokeAsync ( async ( ) =>
127127 {
128- return renderer
129- . UnhandledException
130- . ContinueWith (
131- x => Task . FromException < T > ( x . Result ) ,
132- CancellationToken . None ,
133- TaskContinuationOptions . OnlyOnRanToCompletion | TaskContinuationOptions . ExecuteSynchronously ,
134- TaskScheduler . FromCurrentSynchronizationContext ( ) ) ;
128+ var exception = await renderer . UnhandledException ;
129+ return Task . FromException < T > ( exception ) ;
135130 } ) . Unwrap ( ) ;
136131
137132 return Task
0 commit comments