diff --git a/src/Aspire.Hosting/Dcp/DcpExecutor.cs b/src/Aspire.Hosting/Dcp/DcpExecutor.cs index 425bd739a05..02497a8796c 100644 --- a/src/Aspire.Hosting/Dcp/DcpExecutor.cs +++ b/src/Aspire.Hosting/Dcp/DcpExecutor.cs @@ -789,7 +789,7 @@ private async Task CreateContainersAndExecutablesAsync(CancellationToken cancell var containersTask = CreateContainersAsync(toCreate.Where(ar => ar.DcpResource is Container), cancellationToken); var executablesTask = CreateExecutablesAsync(toCreate.Where(ar => ar.DcpResource is Executable), cancellationToken); - await Task.WhenAll(containersTask, executablesTask).ConfigureAwait(false); + await Task.WhenAll(containersTask, executablesTask).WaitAsync(cancellationToken).ConfigureAwait(false); } private void AddAllocatedEndpointInfo(IEnumerable resources) @@ -1084,10 +1084,11 @@ async Task CreateResourceExecutablesAsyncCore(IResource resource, IEnumerable(); foreach (var group in executableResources.GroupBy(e => e.ModelResource)) { - tasks.Add(CreateResourceExecutablesAsyncCore(group.Key, group, cancellationToken)); + // Force this to be async so that blocking code does not stop other executables from being created. + tasks.Add(Task.Run(() => CreateResourceExecutablesAsyncCore(group.Key, group, cancellationToken), cancellationToken)); } - return Task.WhenAll(tasks); + return Task.WhenAll(tasks).WaitAsync(cancellationToken); } finally { @@ -1097,9 +1098,6 @@ async Task CreateResourceExecutablesAsyncCore(IResource resource, IEnumerable CreateContainerAsyncCore(cr, cancellationToken), cancellationToken)); } - await Task.WhenAll(tasks).ConfigureAwait(false); + await Task.WhenAll(tasks).WaitAsync(cancellationToken).ConfigureAwait(false); } finally { @@ -1351,9 +1350,6 @@ async Task CreateContainerAsyncCore(AppResource cr, CancellationToken cancellati private async Task CreateContainerAsync(AppResource cr, ILogger resourceLogger, CancellationToken cancellationToken) { - // Force async execution - await Task.Yield(); - await _executorEvents.PublishAsync(new OnResourceStartingContext(cancellationToken, KnownResourceTypes.Container, cr.ModelResource, cr.DcpResource.Metadata.Name)).ConfigureAwait(false); var dcpContainerResource = (Container)cr.DcpResource;