DistributedApplication.RunAsync(CancellationToken) Method

Definition

Runs an application and returns a Task that only completes when the token is triggered or shutdown is triggered and all IHostedService instances are stopped.

public virtual System.Threading.Tasks.Task RunAsync (System.Threading.CancellationToken cancellationToken = default);
abstract member RunAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.RunAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function RunAsync (Optional cancellationToken As CancellationToken = Nothing) As Task

Parameters

cancellationToken
CancellationToken

The token to trigger shutdown.

Returns

The Task that represents the asynchronous operation.

Remarks

When the .NET Aspire app host is launched via RunAsync(CancellationToken) there are two possible modes that it is running in:

Developers extending the .NET Aspire application model should consider the lifetime of IHostedService instances which are added to the dependency injection container. For more information on determining the mode that the app host is running in refer to DistributedApplicationExecutionContext.

Applies to