private static async Task RunAsync(this IAppHost host, CancellationToken token, string shutdownMessage) { using (host) { //await host.StartAsync(token); //var hostingEnvironment = host.Services.GetService<IHostingEnvironment>(); //var applicationLifetime = host.Services.GetService<IApplicationLifetime>(); //var options = host.Services.GetRequiredService<WebHostOptions>(); //if (!options.SuppressStatusMessages) //{ // Console.WriteLine($"Hosting environment: {hostingEnvironment.EnvironmentName}"); // Console.WriteLine($"Content root path: {hostingEnvironment.ContentRootPath}"); // var serverAddresses = host.ServerFeatures.Get<IServerAddressesFeature>()?.Addresses; // if (serverAddresses != null) // { // foreach (var address in serverAddresses) // { // Console.WriteLine($"Now listening on: {address}"); // } // } // if (!string.IsNullOrEmpty(shutdownMessage)) // { // Console.WriteLine(shutdownMessage); // } //} await host.WaitForTokenShutdownAsync(token); } }
/// <summary> /// Returns a Task that completes when shutdown is triggered via the given token, Ctrl+C or SIGTERM. /// </summary> /// <param name="host">The running <see cref="IAppHost"/>.</param> /// <param name="token">The token to trigger shutdown.</param> public static async Task WaitForShutdownAsync(this IAppHost host, CancellationToken token = default) { var done = new ManualResetEventSlim(false); using (var cts = CancellationTokenSource.CreateLinkedTokenSource(token)) { AttachCtrlcSigtermShutdown(cts, done, shutdownMessage: string.Empty); await host.WaitForTokenShutdownAsync(cts.Token); done.Set(); } }