I'm trying to run multiple Task using async but when execution reaches WhenAll() this method call never returns.
List<Task> tasks = new(); tasks.Add(Task.Run( async () => viewModel.Customers = await CustomerService.GetAllAsync())); tasks.Add(Task.Run( async () => viewModel.Orders = await OrderService.GetAllAsync())); await Task.WhenAll(tasks.ToArray()); EDIT:
I was able to debug execution all the way into CircuitHost.cs, and on line 125 it stops there.
Here's the stack trace at line 125:
async CircuitHost.<>c__DisplayClass36_0.<InitializeAsync>b__0()at C:\Users\David\AppData\Roaming\JetBrains\Rider2022.1\resharper-host\SourcesCache\d848ab5bf79df2599514458b1cacef69f49ae55787993acba112f74d5315a7\CircuitHost.cs:line 125 AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost.<>c__DisplayClass36_0.<<InitializeAsync>b__0>d>() AsyncTaskMethodBuilder.Start<Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost.<>c__DisplayClass36_0.<<InitializeAsync>b__0>d>() CircuitHost.<>c__DisplayClass36_0.<InitializeAsync>b__0() RendererSynchronizationContext.<>c.<<InvokeAsync>b__9_0>d.MoveNext() AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__9_0>d>() AsyncVoidMethodBuilder.Start<Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__9_0>d>() RendererSynchronizationContext.<>c.<InvokeAsync>b__9_0() RendererSynchronizationContext.ExecuteSynchronously() RendererSynchronizationContext.ExecuteSynchronouslyIfPossible() RendererSynchronizationContext.InvokeAsync() RendererSynchronizationContextDispatcher.InvokeAsync() CircuitHost.InitializeAsync()at C:\Users\David\AppData\Roaming\JetBrains\Rider2022.1\resharper-host\SourcesCache\d848ab5bf79df2599514458b1cacef69f49ae55787993acba112f74d5315a7\CircuitHost.cs:line 100 ComponentHub.<StartCircuit>d__13.MoveNext() AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.Components.Server.ComponentHub.<StartCircuit>d__13>() AsyncValueTaskMethodBuilder<string>.Start<Microsoft.AspNetCore.Components.Server.ComponentHub.<StartCircuit>d__13>() ComponentHub.StartCircuit() [Lightweight Method Call] DefaultHubDispatcher<ComponentHub>.<ExecuteMethod>d__23.MoveNext() AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>.<ExecuteMethod>d__23>() AsyncValueTaskMethodBuilder<object>.Start<Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>.<ExecuteMethod>d__23>() DefaultHubDispatcher<ComponentHub>.ExecuteMethod() DefaultHubDispatcher<ComponentHub>.ExecuteHubMethod() DefaultHubDispatcher<ComponentHub>.<<Invoke>g__ExecuteInvocation|18_0>d.MoveNext() AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>.<<Invoke>g__ExecuteInvocation|18_0>d>() AsyncTaskMethodBuilder.Start<Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>.<<Invoke>g__ExecuteInvocation|18_0>d>() DefaultHubDispatcher<ComponentHub>.<Invoke>g__ExecuteInvocation|18_0() DefaultHubDispatcher<ComponentHub>.<Invoke>d__18.MoveNext() AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>.<Invoke>d__18>() AsyncTaskMethodBuilder<bool>.Start<Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>.<Invoke>d__18>() DefaultHubDispatcher<ComponentHub>.Invoke() DefaultHubDispatcher<__Canon>.<>c.<ProcessInvocation>b__17_0() ChannelBasedSemaphore.<RunTask>d__7<(DefaultHubDispatcher<ComponentHub>, HubMethodDescriptor, HubConnectionContext, HubMethodInvocationMessage)>.MoveNext() AsyncMethodBuilderCore.Start<Microsoft.AspNetCore.SignalR.Internal.ChannelBasedSemaphore.<RunTask>d__7<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage)>>() AsyncTaskMethodBuilder.Start<Microsoft.AspNetCore.SignalR.Internal.ChannelBasedSemaphore.<RunTask>d__7<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage)>>() ChannelBasedSemaphore.RunTask<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage)>() ChannelBasedSemaphore.RunAsync<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher<Microsoft.AspNetCore.Components.Server.ComponentHub>, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage)>() DefaultHubDispatcher<ComponentHub>.ProcessInvocation() DefaultHubDispatcher<__Canon>.DispatchMessageAsync() HubConnectionHandler<ComponentHub>.<DispatchMessagesAsync>d__20.MoveNext() AsyncTaskMethodBuilder<VoidTaskResult>.AsyncStateMachineBox<HubConnectionHandler<ComponentHub>.<DispatchMessagesAsync>d__20>.ExecutionContextCallback() ExecutionContext.RunFromThreadPoolDispatchLoop() AsyncTaskMethodBuilder<VoidTaskResult>.AsyncStateMachineBox<HubConnectionHandler<ComponentHub>.<DispatchMessagesAsync>d__20>.MoveNext() AsyncTaskMethodBuilder<VoidTaskResult>.AsyncStateMachineBox<HubConnectionHandler<ComponentHub>.<DispatchMessagesAsync>d__20>.ExecuteFromThreadPool() ThreadPoolWorkQueue.Dispatch() PortableThreadPool.WorkerThread.WorkerThreadStart() Thread.StartCallback() [Native to Managed Transition] 
viewModel.Customersproperty, and theCustomerService.GetAllAsync()method? I assume that the Orders-related counterpart is similar. You could test this assumption by commenting out the Orders-related part, and see if the problem persists with a single task in thetaskslist.Task.Runwith this customRunmethod:static async Task Run(Func<Task> action) => await action();, and see if it makes any difference?