HostingHostBuilderExtensions.RunConsoleAsync Method

Definition

Overloads

RunConsoleAsync(IHostBuilder, CancellationToken)

Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

RunConsoleAsync(IHostBuilder, Action<ConsoleLifetimeOptions>, CancellationToken)

Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

RunConsoleAsync(IHostBuilder, CancellationToken)

Source:
HostingHostBuilderExtensions.cs
Source:
HostingHostBuilderExtensions.cs
Source:
HostingHostBuilderExtensions.cs

Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Threading.Tasks.Task RunConsoleAsync(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Threading.CancellationToken cancellationToken = default);
C#
public static System.Threading.Tasks.Task RunConsoleAsync(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Threading.CancellationToken cancellationToken = default);

Parameters

hostBuilder
IHostBuilder

The IHostBuilder to configure.

cancellationToken
CancellationToken

A CancellationToken that can be used to cancel the console.

Returns

A Task that only completes when the token is triggered or shutdown is triggered.

Attributes

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

RunConsoleAsync(IHostBuilder, Action<ConsoleLifetimeOptions>, CancellationToken)

Source:
HostingHostBuilderExtensions.cs
Source:
HostingHostBuilderExtensions.cs
Source:
HostingHostBuilderExtensions.cs

Enables console support, builds and starts the host, and waits for Ctrl+C or SIGTERM to shut down.

C#
[System.Runtime.Versioning.UnsupportedOSPlatform("android")]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Threading.Tasks.Task RunConsoleAsync(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, Action<Microsoft.Extensions.Hosting.ConsoleLifetimeOptions> configureOptions, System.Threading.CancellationToken cancellationToken = default);
C#
public static System.Threading.Tasks.Task RunConsoleAsync(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, Action<Microsoft.Extensions.Hosting.ConsoleLifetimeOptions> configureOptions, System.Threading.CancellationToken cancellationToken = default);

Parameters

hostBuilder
IHostBuilder

The IHostBuilder to configure.

configureOptions
Action<ConsoleLifetimeOptions>

The delegate for configuring the ConsoleLifetime.

cancellationToken
CancellationToken

A CancellationToken that can be used to cancel the console.

Returns

A Task that only completes when the token is triggered or shutdown is triggered.

Attributes

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)